- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2020 01:42 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2020 02:24 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2020 01:51 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2020 01:52 AM
HI,
if (currentFieldNames[i].toString() == getResult.metric.name) { getRisk.currentFieldNames[i].setDisplayValue(getResult.string_value);
getRisk.update();
}
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2020 02:19 AM
I tried this, but it is coming as undefined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2020 02:25 AM
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);