how to get values for array list and record field from property

String
Kilo Sage

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";

 

1 ACCEPTED SOLUTION

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

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

View solution in original post

6 REPLIES 6

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

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

vishalAg20
Tera Contributor
 var res = JSON.parse(responsebody);
             //   gs.log("CMDB_CI_INTEGRATION: Parsed response: " + JSON.stringify(res));

 

                // Access the Configuration Items property
                var configurationItems = res['Configuration Items']; // Adjust according to actual property name

 

                // Validate and process the configurationItems
                if (Array.isArray(configurationItems)) {
                    gs.log("CMDB_CI_INTEGRATION: Number of configuration items received: " + configurationItems.length);
 
 
      var configurationItems = res['Configuration Items']; // Adjust according to actual property name
This property not working How can i do fetch cmdb data