- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2021 10:26 PM
Hi Team,
we are having a custom scripted get API and we have few hard code values as well, So we are using the property to fetch the values. But we have to fetch for array list and user record values ,Any suggestion please
hard_code_values :abc,xyz,test,test1,test2,Testing,Regular testing"
var groupValues = gs.getProperty('hard_code_values').toString();
var arr = groupValues.split(',');
var values=[abc,xyz,test,test1,test2]
var grInc = new GlideRecord("incident");
grInc.initialize();
grInc.caller_id = "Testing";
grInc.contact_type = "Regular testing";
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 03:37 AM
Hi,
So are you sure the 1st 5 values from that property are to be checked for query parameters and next 2 are to be used for inserting?
if yes then update as this
Array will be running only for 1st 5 values
var groupValues = gs.getProperty('hard_code_values').toString();
var arr = groupValues.split(',');
var emptyValue = []; // this array holds fields for which there isn't any value from query Params
for(var i=0;i<4;i++){
if(queryParams[arr[i]][0] == '' && queryParams[arr[i]][0] == undefined){
emptyValue.push(arr[i].toString());
}
}
// now you can determine if that array has any field or not
if(emptyValue.length > 0){
// means some field is empty so give error
}
var grInc = new GlideRecord("incident");
grInc.initialize();
grInc.short_description = queryParams.abc[0];
grInc.description = queryParams.xyz[0];
grInc.note = queryParams.test[0];
grInc.worknote = queryParams.test1[0];
grInc.subnote = queryParams.test2[0];
grInc.caller_id = arr[5]; // 6th value
grInc.contact_type = arr[6]; // 7th value
var ID = grInc.insert();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2021 10:48 PM
Hi,
using those values from property what needs to be done
you can iterate it like this
var groupValues = gs.getProperty('hard_code_values').toString();
var arr = groupValues.split(',');
for(var i=0;i<arr.length;i++){
var grInc = new GlideRecord("incident");
grInc.initialize();
grInc.caller_id = "Testing";
grInc.contact_type = "Regular testing";
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2021 11:34 PM
Hi
thanks for ur quick reply
inbound json:
{"abc":["file error"],"xyz":[" hello"],"test":["Application"],"test1":["Azure"],"test2":["issue"]}
below Get scripts API as follows
var mandatoryFields = ['abc','xyz','test','test1','test2'];//need to fetch from properties
//having some logic for validation the mandatory fields from the incoming json .
//after validation over we are inserting the values to incident record along with few hard codes value
var grInc = new GlideRecord("incident");
grInc.initialize();
grInc.short_description = queryParams.abc[0];
grInc.description = queryParams.xyz[0];
grInc.note =test.xyz[0];
grInc.worknote =test1.xyz[0];
grInc.subnote =test2.xyz[0];
grInc.caller_id = "Testing";//need to fetch from properties
grInc.contact_type = "Regular testing";//need to fetch from properties inc
var ID = grInc.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:09 AM
Hi,
So you want to validate out of thoese mandatory fields which are empty in the incoming json?
update as this
var groupValues = gs.getProperty('hard_code_values').toString();
var arr = groupValues.split(',');
var emptyValue = []; // this array holds fields for which there isn't any value from query Params
for(var i=0;i<arr.length;i++){
if(queryParams[arr[i]][0] == '' && queryParams[arr[i]][0] == undefined){
emptyValue.push(arr[i].toString());
}
}
// now you can determine if that array has any field or not
if(emptyValue.length > 0){
// means some field is empty so give error
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 01:40 AM
Hi,
sorry, if I am confusing you.!
hard_code_valus='abc','xyz','test','test1','test2','Testing','Regular testing'
1.The first five('abc','xyz','test','test1','test2') I have to fetch from properties and validate in my incoming json having that parameters or not
2.Remaining values(Testing,Regular testing) from properties have to insert into incident record as below
var grInc = new GlideRecord("incident");
grInc.initialize();
grInc.caller_id = "Testing";
grInc.contact_type = "Regular testing";