setDisplayValue() not working for scoped app

ServiceNow SA
Kilo Guru

Hi Team,

I have a requirement where i need to copy my Risk assessment response to my Risk forms. But i am not able to assign values.

Here is my code snippet:

 var getResult = new GlideRecord('asmt_metric_result');
 getResult.addEncodedQuery('source_id=' + current.sys_id);
 getResult.addNotNullQuery('string_value');
 getResult.query();
 if (getResult.next()) {
		
        var getRisk = new GlideRecord('sn_risk_risk');
        getRisk.get(current.sys_id);
        var currentFieldNames = [];
		
        for (var f in getRisk) currentFieldNames.push(f);

        for (var i = 0; i < currentFieldNames.length; i++) {

           
            if (currentFieldNames[i] == getResult.metric.name) {
				
		getRisk.currentFieldNames[i].setDisplayValue(getResult.string_value);		

                getRisk.update();
            }
        }
               
            }

 

How can i set risk field to the value of the response?

PS: the backend value of question and risk field is same.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please try this and let me know if it works

if (currentFieldNames[i] == getResult.metric.name) {

getRisk[currentFieldNames[i]].setDisplayValue(getResult.string_value);        

getRisk.update();
}

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

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

View solution in original post

7 REPLIES 7

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

setDisplayValue works in scoped app. There is something wrong with code.
https://community.servicenow.com/community?id=community_question&sys_id=506acd89dbda049023f4a345ca96...


Thanks,
Ashutosh

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

if (currentFieldNames[i].toString() == getResult.metric.name) { getRisk.currentFieldNames[i].setDisplayValue(getResult.string_value);

getRisk.update();

}


Thanks,
Ashutosh

I tried this, but it is coming as undefined.

It is not able to get the array element. Eg, if "category" field exists both in my Risk table and assessment.

Then value of category should be copied from assessment response to risk table.

But below line is not considering category field  as array element:

getRisk.currentFieldNames[i].setDisplayValue(getResult.string_value);