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

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

Thank you so much Ankur. It worked. 

How can i miss on this 🙂 

Glad that it helped.

Regards
Ankur

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