Convert the Sys id to string for multirow variable set fields in arecord producer how to achieve ?

sree10
Tera Contributor

Hello Everyone,

 

We have a requirement where we need to reference all the record producer fields in a specific field called the "Details Section." Within this section, we are using a MultiRow Variable Set. However, we are encountering an issue when trying to convert a sysid to a string, particularly when the field is a reference field linked to the sysuser table. Although we attempted to use the getDisplayValue() method and tried converting it to a string, the entire value disappears from the record producer's Details Section when we do so. I would appreciate any guidance or assistance you could provide to help us resolve this issue. Please refer to the attached screenshot for further context. Thank you in advance for your support.

4 REPLIES 4

sheryl
Tera Expert

Are you trying to get the user name field instead of the sys_id?  In your screenshot, it looks like you have the sys_id.  Can you share your code that is pushing this data into the details section?

sree10
Tera Contributor
 producer.purchasing_details.getLabel() + ': ' + producer.purchasing_details + '\n' +
 this is script I have written in the record producer script for getting the values of MRVS in a record producer please find the result in below screenshot
sree10_0-1741054220671.png

 here  we are getting all the fields details except reference fileds .I have created one more field with single line and given the reference filed as dependent their we are getting the result but now I am planning to hide the sys id filed how to achieve this method please help.

@sree10

purchasing_details is MRVS

So it will give you json string.

you need to parse it and get the values.

Remember it will give sysId for reference and list collector within MRVS. You will have to use explicit GlideRecord to get the display value by querying the table with that sysId

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

Hemant Ch
Tera Expert

Please use this code as reference 

(function() {
    // JSON input
    var purchasing_details = [{
        "sys_id": "2823923339303"
    }];
    var sysId = purchasing_details[0].sys_id;
    
    // GlideRecord to fetch user details
    var userGR = new GlideRecord('sys_user'); // sys_user table
    if (userGR.get(sysId)) {
        var userLocation = userGR.location.getDisplayValue(); // Fetch Location
        var userDepartment = userGR.department.getDisplayValue(); // Fetch Department
        
        // Output the details
        gs.info("User Location: " + userLocation);
        gs.info("User Department: " + userDepartment);
    } else {
        gs.info("User not found for sys_id: " + sysId);
    }
})();