How to make reference field mandatory for Rest API

Upender
Giga Expert

Hi Guys,

My requirement is to enter a valid value in reference field using Rest API.

For that I have created a Data Policy which is not working, if I enter invalid value or value not in reference table, record is created in the table with a null or empty value with Response Status code as 201 Created.

Even I tried to create business Rule. Record is created giving Response Status code as 201 Created and it is throwing an error on UI side if I enter invalid value.

I have created a Data Policy on another choice field on the same table which is working fine it is giving Response Status code as 201 Created If I enter a valid choice. If I enter a choice other than choices in the field it throws an error with Response Status Code 403 Forbidden.

Is there is a way to make a reference field Mandatory for Rest API.

Thanks in advance

Upender

1 ACCEPTED SOLUTION

Upender
Giga Expert

I have created a business rule to check if the value enter in reference field is present in the reference table or not. if the value not present in reference table don't allow to create the record in the table.




var a = [];


var gr = new GlideRecord ('u_mon_collector_config');   //Reference table


gr.query();


while(gr.next()){


a += gr.sys_id;    


}


if((a.indexOf(current.u_monitoring_system) == -1) || (current.u_monitoring_system =='')) //Reference field


{


gs.addErrorMessage("Fill in valid value in Monitoring System field");


current.setAbortAction(true);


}






Regards,


Upender


View solution in original post

10 REPLIES 10

Hi Upender,



When you use rest api to insert a record in that table not in the reference table so insertion of record data policy check that it's having the value or not



In Reference table data is not match with any record it will create a new record in reference table


Hi Chandu,


I checked Reference table no record is created in two weeks. So reference table is not storing new values (invalid values enter through Rest API).





Regards,


Upender


you want to restrict those values insertion through rest api



When a record insertion automatically (rest ,soap. data source,scripts) it only check with form having the value will not check for the it's having the valid data or not


HI Chandu,


I want to restrict creation of record in table if the User enters value in reference field, value that is not present in the reference table through rest, soap, data source or Scripts.



Is there is a way to do this




Thanks,


Upender


Chandu Telu
Tera Guru
Tera Guru

Hi Upender,



Check the below link it will help you


Data Validation in Scripted REST API