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

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