Client Script not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 01:56 AM
function onLoad() {

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 02:25 AM
Hi @aagman4,
Try this:
function onLoad() {
g_form.addInfoMessage('hi');
var arr = [];
var associatedRisks = new GlideRecord('sn_risk_m2m_risk_control');
associatedRisks.addQuery('sn_compliance_control', g_form.getUniqueValue());
associatedRisks.query(getAssociatedRisks);
}
function getAssociatedRisks(associatedRisks){
while(associatedRisks.next()){
arr.push(associatedRisks.sn_risk_risk.sys_id.toString());
}
g_form.addInfoMessage('hello');
var inherentRisk = new GlideRecord('sn_risk_advanced_risk_assessment_instance');
inherentRisk.addQuery('risk.sys_id', 'IN' ,arr);
inherentRisk.addQuery('state', '7');
inherentRisk.orderByDesc('final_inherent_score');
inherentRisk.query(getInherentRisk);
}
function getInherentRisk(inherentRisk){
if(inherentRisk.next()){
var riskScore = inherentRisk.summary_inherent_risk_score;
if(riskScore.indexOf('High') > -1){
g_form.setValue('u_overall_risk_rating','High');
}
else if(riskScore.indexOf('Moderate') > -1 || riskScore.indexOf('Medium') > -1){
g_form.setValue('u_overall_risk_rating','Medium');
}
else{
g_form.setValue('u_overall_risk_rating','Low');
}
}
}
This can work fine this way, but it would be better to use a GlideAjax next time. Worth reading into 😉
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 04:03 AM
Its not working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 04:10 AM
What is not working?
Are you getting some of the infomessages or not?
Are you sure your queries are correct?
Are your if statements correct? riskScore might be a getDisplayValue instead of your value for example.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 04:58 AM
I would suggest using GlideAjax or query business rule on that table.
What did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader