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

Chandu Telu
Tera Guru
Tera Guru

HI Upender,



It working for me,



i think it's creating the record in that reference table may be it's doesn't have the display value


find_real_file.png



find_real_file.png


Hi Chandu,


Record is creating in actual table not in reference table.



find_real_file.png



find_real_file.png


find_real_file.png




find_real_file.png






Regards,


Upender


Hi Upender,




Check the display value of this record by hovering on Information icon



If it's available it's issue with display value


find_real_file.png


Hi Chandu,


I hover the Icon it showed me "no preview available".


Monitoring System field "4444"   is invalid Value. so it is not stored in reference table.


But record is created in Monitoring Collecters table with empty value in Monitoring System field.



find_real_file.png




Regards,


Upender