Convert sys id to string value

ASHLE CRAIG
Giga Contributor

Hi, I am testing my script in the background script. It is printing out sysid values. How can i change to more human readable and convert the output to a string. 

var user = gs.getUserID();
        var ac = new GlideRecord('cmdb_ci_service_discovered');
        ac.addQuery('owned_by', user);
        ac.query();
        var userArr = [];
        while (ac.next())
            {
            userArr.push(ac.sys_id.toString());
            }
                gs.info("User: " + userArr);
 
        var ritm = new GlideRecord('sc_item_option_mtom');
        ritm.addEncodedQuery('request_item.cat_item=03d635091b2195101953ca242a4bcb60^sc_item_option.item_option_new=b649798d1b2195101953ca242a4bcbd4^sc_item_option.valueIN' + userArr);
        ritm.query();
        while (ritm.next())
            {
            var tm = new GlideRecord('sc_item_option_mtom');
            tm.addEncodedQuery('request_item.cat_item=03d635091b2195101953ca242a4bcb60^sc_item_option.item_option_new=9e481bd99769915048439904a253afba^request_item=' + ritm.request_item);
            tm.query();       
                         while (tm.next())
                 {
                                    var gr = new GlideRecord('cmdb_group');
                                    gr.addEncodedQuery('group_nameIN'+ tm.group_name);
                                    gr.query();
                                                      
 
                    }
          gs.info("RITM: "+ritm.sys_id);
          gs.info("Target Machine: "+tm.sys_id);
          gs.info("Group Name: "+tm.sys_id);
}
1 ACCEPTED SOLUTION

Zach Koch
Giga Sage
Giga Sage

If by string, you mean the Display value of a field, then you can use getDisplayValue('field_name'). Reference fields will always give you the sys_id of the record if you grab it directly, if you want the display value, use the same function.

If this resolved your issue, please mark this correct and helpful, thanks!

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

View solution in original post

1 REPLY 1

Zach Koch
Giga Sage
Giga Sage

If by string, you mean the Display value of a field, then you can use getDisplayValue('field_name'). Reference fields will always give you the sys_id of the record if you grab it directly, if you want the display value, use the same function.

If this resolved your issue, please mark this correct and helpful, thanks!

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!