How to Set Mandatory Fields in a Scripted REST API without data policies

Lavanya R1
Tera Contributor

Hello,

 

I wanted to know how to set mandatory fields through a scripted REST API without enforcing a data policy. I am creating a record in a table based on the request of the payload. I want to make some fields mandatory, only then it should accept the request, else it should throw an error.

 

Please let me know how to achieve this.

 

Thanks in Advance

13 REPLIES 13

@Lavanya R1 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar , 

 

I tried writing onbefore script but it didn't work in my case. And i have the same issue which Lavanfya explained earlier in this case. 

I have written POST method and there I am loading the data to staging table and created a transform map. and in transform map onbefore script section I was doing this manadtory field validation. But still in my case the data is loaded in the incident table as well as staging table. Please guide here. 

 

Thanks,

Diksha

@Lavanya R1 

it would be nice if you share complete script

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

The thing is the script is little messed up since I was trying multiple things together! Since I am stuck on this particular part I shared only that part of the script!