Issue with setting the REFERENCE field

Suggy
Giga Sage

On INC form, we have a custom field "u_portfolio" referring to Service Portfolio table.

Below is the script where need to set 'Assigned To' and 'Portfolio' fields.

 

var rec = new GlideRecord("incident");
rec.addEncodedQuery("number=INC0000019");
rec.query();
if(rec.next()){
rec.assigned_to = 'Andrew Och'; // This line WORKS
rec.u_portfolio = 'Collaboration'; //This line FAILS
rec.update();
}

 

Question - Why setting Assigned to Reference field works but fails for Portfolio reference field?

PS - The dictionary attribute is EMPTY for both the fields.

7 REPLIES 7

Maddysunil
Kilo Sage

@Suggy 

when setting a reference field using GlideRecord, you need to set it with a reference value rather than just a string value. The reason why setting the assigned_to field works but the u_portfolio field fails is likely because the assigned_to field is a reference field that accepts a string value representing the sys_id of the user record, while the u_portfolio field is a reference field that refers to another table (Service Portfolio table in this case).

 

 

var rec = new GlideRecord("incident");
rec.addEncodedQuery("number=INC0000019");
rec.query();
if (rec.next()) {
    rec.assigned_to = 'Andrew Och'; // This line WORKS
    var portfolio = new GlideRecord('u_portfolio_table_name'); // Replace 'u_portfolio_table_name' with the actual table name
    if (portfolio.get('name', 'Collaboration')) { // Assuming 'Collaboration' is the name of the portfolio you want to set
        rec.u_portfolio = portfolio.sys_id;
        rec.update();
    } else {
        gs.error("Portfolio not found: Collaboration");
    }
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

You mentioned "while the u_portfolio field is a reference field that refers to another table "

FYI, "assigned_to" is also a reference field that refers to another table.

Suggy
Giga Sage

Anyone?