Set a field by condition when CRUD via API

I’m using REST API to CRUD a DocType. When creating a Doc, I send either mobile number or landline number.

I need to set Is Primary Phone and Is Primary Mobile fields depending on the first digit in the phone number.

Should I use Document Actions, or Server Script to perform this task?

Hi @charleslcso,

Both Document Actions and Server Scripts can be used to perform this task, but the choice between the two depends on your specific use case and requirements.

Document Actions are executed on the client side, i.e., within the user’s browser, when a specific event occurs. In this case, you can use a Document Action to check the first digit of the phone number and set the Is Primary Phone and Is Primary Mobile fields accordingly. However, using a Document Action can be less secure, as the client-side code can be modified by the user, potentially compromising the integrity of your data.

On the other hand, Server Scripts are executed on the server side, i.e., on the server, and can provide more security and control over the data. In this case, you can use a Server Script to check the first digit of the phone number and set the Is Primary Phone and Is Primary Mobile fields. This approach is more secure, as the server-side code cannot be modified by the user.

Therefore, if you prioritize security and data integrity, you should use a Server Script. However, if you need to perform this task on the client side, a Document Action can be used.

We just share the suggestion, not a solution.

I hope this helps.
Thank You!

2 Likes

Thank you thank you. Much appreciated!