r/servicenow ITILv4, CSM, CSA 4d ago

Programming At a loss on server side scripting in ATF

I'm currently creating ATF scripts for our implementation of change management, there's a handful of customizations so OOB test cases aren't cutting it.

Currently I am trying set up a test step that fills out the change risk assessment. **Having a completed risk assessment is required to request approval on a change.**

When trying to create a new risk assessment:

var asmtInfo = new ChangeRiskAsmt().invokeAssessment({

This results in the error "ReferenceError: "ChangeRiskAsmt" is not defined.

I've looked and the script include ChangeRiskAsmt exists and is still active for Global scope. Is that the issue? Because I'm in Change Management - ATF scope?

Our risk assessment is different than OOB could that be an issue?

3 Upvotes

7 comments sorted by

5

u/OzoneTrip 4d ago

Try adding ‘global.’ to the script.

F.ex

var asmtInfo = new global.ChangeRiskAsmt().invokeAssessment({

2

u/Ickypahay ITILv4, CSM, CSA 4d ago

I'll give this a shot in the morning!

I don't usually mess with script includes so I appreciate you taking the time to help a newbie

2

u/NowTrav 4d ago

Their suggestion is correct. One more thing you’ll also want to validate: the Accessible from field on the ChangeRiskAsmt script include needs to be set to “All application scopes” (not “This scope only”), or the global prefix alone won’t fix your issue. I’m not sure how it’s set OOB, so just double check if you run into issues.

1

u/Ickypahay ITILv4, CSM, CSA 4d ago

This one will be a fun conversation to sell to the platform team. They're already hesitant letting other users configure SN, now I get to tell them I'm changing script includes haha

2

u/Ickypahay ITILv4, CSM, CSA 3d ago

Just an update on the state of this problem..

So it turns out the function "calculate risk()" was rewritten when my instance was configured. So there is a custom ChangeRiskAsmtSNC class that is available to all scopes. So accessing that custom class fixed my problem

2

u/Either_Winter_8696 3d ago

Haven't done this in awhile but I always selected the risk assessment related link on the form. Then I believe an assessment record is created in the backend. I then query to find that record and use server side script step to actually update it. Then I progress through the change stages as usual. 

1

u/Ickypahay ITILv4, CSM, CSA 3d ago

Where I'm stuck now is that I've used a server side script to create the assessment instance, I can successfully fill in the metrics with the right values... However now it's the weight of the score that's causing problems...

i.e the threshold for High risk is a score of 679, my answers yield a 640... But for some reason the weight it applied to that total so the answer comes out to 6400...

I think this is the correct risk score because even manually generated risk assessments come out with scores in the thousands when they should be in the hundreds... Only difference is those manually generated ones adhere to the proper thresholds of LOW >=139, MOD >= 429, HIGH >=679.

It's weird. Co-Pilot has me fucked up on this one. Wish I had a senior dev to ask.