Set Field Values Using Server Side Run Script

Gerald Onyia
Kilo Guru

My team and I have encountered an issue when trying to automate a service catalog item.

We cannot set some variables due to their onChange and onLoad rule/client script. We have many catalog items like this, and need a way to automate them. I've heard using a Run Server Side Script to set the field values might work. I am not sure how to go about doing this. I would appreciate any guidance on how to do this.

6 REPLIES 6

Tim Deniston
Mega Sage
Mega Sage

When adding a test step, select 'Server' on the left and then 'Run Server Side Script' on the right. 

find_real_file.png

 

Then, your 'Test script' box can contain JavaScript that can update records. I found some OOB test steps that are set up to update records. See this one as an example: https://[YOURINSTANCENAME].service-now.com/nav_to.do?uri=sys_atf_step.do?sys_id=9000a4560b10220050192f15d6673a3e 

find_real_file.png

Hello,

Thanks for the response!

So I inserted the Run Server Side Script in between my Open and Order Catalog Item, which seems to have been successful.

However, based on the Failure in Step 6, the Test seems to have lost its connection to the 'Open a Catalog Item' Step, because it's essentially stating that no form/catalog item is opened.

find_real_file.png

Any more guidance would be appreciated. See below for my Run Server Side Script:

find_real_file.png

James Gragston
Tera Guru

Gerald,

If you don't need any logic to determine what field values need to be populated, you can use the 'Set Values' workflow activity:

find_real_file.png

 

However, if you're values will be determined by logic, you should use a 'Run Script' where you can change field values via the current object:

current.short_description = "New text in the short description";

Keep in mind the current object is based on the table your workflow is running on.

Hope this helped!

Hello,

Thanks for the response. Trying this resulted in the following error:

Full logging from step execution:
10:41:05.755: Loading script: jasmine_lib/jasmine31.js
10:41:05.771: Root cause of JavaScriptException: org.mozilla.javascript.NativeError
JavaScript evaluation error on:
var assertEqual = function(assertion) {
if (!(assertion.value == assertion.shouldbe)) {
gs.info("Assertion failed: " + assertion.name + " should have been " + assertion.shouldbe +
" but was " + assertion.value);
throw "Assertion failed";
}
}
try {
var steps = function(step_id){
return step.sibling(step_id);
};
current.u_dmsc_description = "DMS";
} catch (e) {
if (e == 'Assertion failed')
glideTestResultBoolean = false;
else
throw e;
}
: no thrown error
10:41:05.773: JavaScript evaluation error on:
var assertEqual = function(assertion) {
if (!(assertion.value == assertion.shouldbe)) {
gs.info("Assertion failed: " + assertion.name + " should have been " + assertion.shouldbe +
" but was " + assertion.value);
throw "Assertion failed";
}
}
try {
var steps = function(step_id){
return step.sibling(step_id);
};
current.u_dmsc_description = "DMS";
} catch (e) {
if (e == 'Assertion failed')
glideTestResultBoolean = false;
else
throw e;
}
: org.mozilla.javascript.JavaScriptException: TypeError: Cannot set property "u_dmsc_description" of null to "DMS" (sys_atf_step.c4a3446ddbadcc14ecda8396489619fa; line 17): org.mozilla.javascript.gen.sys_atf_step_c4a3446ddbadcc14ecda8396489619fa_254065._c_script_0(sys_atf_step.c4a3446ddbadcc14ecda8396489619fa:17)
org.mozilla.javascript.gen.sys_atf_step_c4a3446ddbadcc14ecda8396489619fa_254065.call(sys_atf_step.c4a3446ddbadcc14ecda8396489619fa)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:563)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3429)
org.mozilla.javascript.gen.sys_atf_step_c4a3446ddbadcc14ecda8396489619fa_254065.call(sys_atf_step.c4a3446ddbadcc14ecda8396489619fa)
org.mozilla.javascript.gen.sys_atf_step_c4a3446ddbadcc14ecda8396489619fa_254065.exec(sys_atf_step.c4a3446ddbadcc14ecda8396489619fa)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:279)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:118)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:82)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:309)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:257)
com.glide.automated_testing_framework.runner.step.JasmineScriptTestRunner.execute(JasmineScriptTestRunner.java:148)
com.glide.automated_testing_framework.runner.step_environment.AbstractServerStepEnvRunner.lambda$processStep$15(AbstractServerStepEnvRunner.java:128)
com.glide.rollback.recording.RollbackRecorder.execute(RollbackRecorder.java:67)
com.glide.automated_testing_framework.util.ATFRollbackUtil.recordOpsInRollbackContext(ATFRollbackUtil.java:80)
com.glide.automated_testing_framework.runner.step_environment.AbstractServerStepEnvRunner.processStep(AbstractServerStepEnvRunner.java:119)
com.glide.automated_testing_framework.runner.step_environment.AbstractServerStepEnvRunner.processSteps(AbstractServerStepEnvRunner.java:95)
com.glide.automated_testing_framework.runner.step_environment.AbstractServerStepEnvRunner.execute(AbstractServerStepEnvRunner.java:44)
com.glide.automated_testing_framework.worker.TestExecutionWorker.executeTestInOrderByBatch(TestExecutionWorker.java:294)
com.glide.automated_testing_framework.worker.TestExecutionWorker.execute(TestExecutionWorker.java:194)
com.glide.automated_testing_framework.TestExecutionProgressWorker.startWork(TestExecutionProgressWorker.java:37)
com.glide.worker.AbstractProgressWorker.startAndWait(AbstractProgressWorker.java:123)
com.glide.worker.HierarchicalProgressWorker.startAndWait(HierarchicalProgressWorker.java:35)
com.glide.worker.BackgroundProgressJob.execute(BackgroundProgressJob.java:59)
com.glide.schedule.JobExecutor.lambda$executeJob$189(JobExecutor.java:108)
com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:111)
com.glide.schedule.JobExecutor.execute(JobExecutor.java:95)
com.glide.schedule.GlideScheduleWorker.executeJob(GlideScheduleWorker.java:236)
com.glide.schedule.GlideScheduleWorker.lambda$process$187(GlideScheduleWorker.java:165)
com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35)
com.glide.schedule.GlideScheduleWorker.process(GlideScheduleWorker.java:165)
com.glide.schedule.GlideScheduleWorker.run(GlideScheduleWorker.java:75)

10:41:05.776: TypeError: Cannot set property "u_dmsc_description" of null to "DMS" (sys_atf_step.c4a3446ddbadcc14ecda8396489619fa; line 17): org.mozilla.javascript.JavaScriptException: TypeError: Cannot set property "u_dmsc_description" of null to "DMS" (sys_atf_step.c4a3446ddbadcc14ecda8396489619fa; line 17): org.mozilla.javascript.gen.sys_atf_step_c4a3446ddbadcc14ecda8396489619fa_254065._c_script_0(sys_atf_step.c4a3446ddbadcc14ecda8396489619fa:17)
org.mozilla.javascript.gen.sys_atf_step_c4a3446ddbadcc14ecda8396489619fa_254065.call(sys_atf_step.c4a3446ddbadcc14ecda8396489619fa)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:563)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3429)
org.mozilla.javascript.gen.sys_atf_step_c4a3446ddbadcc14ecda8396489619fa_254065.call(sys_atf_step.c4a3446ddbadcc14ecda8396489619fa)
org.mozilla.javascript.gen.sys_atf_step_c4a3446ddbadcc14ecda8396489619fa_254065.exec(sys_atf_step.c4a3446ddbadcc14ecda8396489619fa)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:279)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:118)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:82)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:309)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:257)
com.glide.automated_testing_framework.runner.step.JasmineScriptTestRunner.execute(JasmineScriptTestRunner.java:148)
com.glide.automated_testing_framework.runner.step_environment.AbstractServerStepEnvRunner.lambda$processStep$15(AbstractServerStepEnvRunner.java:128)
com.glide.rollback.recording.RollbackRecorder.execute(RollbackRecorder.java:67)
com.glide.automated_testing_framework.util.ATFRollbackUtil.recordOpsInRollbackContext(ATFRollbackUtil.java:80)
com.glide.automated_testing_framework.runner.step_environment.AbstractServerStepEnvRunner.processStep(AbstractServerStepEnvRunner.java:119)
com.glide.automated_testing_framework.runner.step_environment.AbstractServerStepEnvRunner.processSteps(AbstractServerStepEnvRunner.java:95)
com.glide.automated_testing_framework.runner.step_environment.AbstractServerStepEnvRunner.execute(AbstractServerStepEnvRunner.java:44)
com.glide.automated_testing_framework.worker.TestExecutionWorker.executeTestInOrderByBatch(TestExecutionWorker.java:294)
com.glide.automated_testing_framework.worker.TestExecutionWorker.execute(TestExecutionWorker.java:194)
com.glide.automated_testing_framework.TestExecutionProgressWorker.startWork(TestExecutionProgressWorker.java:37)
com.glide.worker.AbstractProgressWorker.startAndWait(AbstractProgressWorker.java:123)
com.glide.worker.HierarchicalProgressWorker.startAndWait(HierarchicalProgressWorker.java:35)
com.glide.worker.BackgroundProgressJob.execute(BackgroundProgressJob.java:59)
com.glide.schedule.JobExecutor.lambda$executeJob$189(JobExecutor.java:108)
com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:111)
com.glide.schedule.JobExecutor.execute(JobExecutor.java:95)
com.glide.schedule.GlideScheduleWorker.executeJob(GlideScheduleWorker.java:236)
com.glide.schedule.GlideScheduleWorker.lambda$process$187(GlideScheduleWorker.java:165)
com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35)
com.glide.schedule.GlideScheduleWorker.process(GlideScheduleWorker.java:165)
com.glide.schedule.GlideScheduleWorker.run(GlideScheduleWorker.java:75)

 

This is my Test Steps:

find_real_file.png

 

With the Run Server Side Script being:

find_real_file.png