Using Image Variable Type to Put In Image Into Knowledge Base Article

IDewar
Tera Expert

Hey there all,

 

What I am trying to do is have a Knowledge Base article created by the fields in a table. Once the record is put into a certain status, it kicks off a Flow which sends it for approval and once approved, it creates a new Knowledge Base article. It does this using a Create Record action and the Article Body is created using a script which basically creates a sting variable which includes the HTML to create the table along with the references to the information (fd_data.trigger.current.u_new_model_details for example) and returns it at the end. When it comes to most of the data from variables (String, HTML, Date, Choice…) this works without issue. However, the issue comes when it comes to the Image variables.

 

When I put the reference to the image directly into the script (fd_data.trigger.current.u_support_flow_diagram for example without any other HTML around it) it puts the sys_id of the picture into the table as text and works without issue. This would make me think that I could simply use it to link to the image and it would work fine. However, when I try to do the following I get an error when running the Flow:

 

<tr style="height: 37.3125px;">\
<td style="width: 193.219px; background-color: rgb(194, 224, 244); height: 37.3125px;"><span style="font-family: verdana, geneva;"><strong><span style="font-size: 10pt;">3.0 Support Flow Diagram</span></strong></span></td>\
<td style="width: 850.657px; height: 37.3125px;" colspan="3"><img src="https://hestest.service-now.com/' + fd_data.trigger.current.u_support_flow_diagram + '.iix" alt="Support Flow Diagram" width="800"></td>\
</tr>\

 

I have tried adding .IsString() as I know that sometimes help but that doesn’t seem to work either. When I replace the reference with the data it contains, the picture shows up perfectly so it’s not an issue with the picture itself. When I run a Test on the Flow, Workflow Studio doesn’t give me anything more than there is an error. If I click Go to Error, it doesn’t do anything, but I know that the error is with the script. When I look at the flow logs, the error it is reporting is:

 

Encountered error executing instruction: OpInstruction{id=246, opClass=com.snc.process_flow.operation.script.InlineScriptOperation, io=Io{input={required_run_time=RefOrValue{value=vanilla, isRef=false}, trigger_current=RefOrValue{value=in.current, isRef=true}, script=RefOrValue{value=(function (inputs, outputs) {outputs.__result = (function (inputs) {

[ALL OF THE SCRIPT]

com.snc.process_flow.exception.OpException: Error: "fd_data" is not defined.,Detail: "fd_data" is not defined.
at com.snc.process_flow.operation.script.ScriptOperationBase.handleScriptResult(ScriptOperationBase.java:64)
at com.snc.process_flow.operation.script.ScriptOperationBase.runScript(ScriptOperationBase.java:52)
at com.snc.process_flow.operation.script.ScriptOperation.run(ScriptOperation.java:75)
at com.snc.process_flow.engine.Operation.run2(Operation.java:90)
at com.snc.process_flow.v2.exec.OpRunner.runOperation(OpRunner.java:75)
at com.snc.process_flow.v2.exec.OpRunner.runOperation(OpRunner.java:69)
at com.snc.process_flow.v2.exec.OpInstructionExecutor.runOperation(OpInstructionExecutor.java:60)
at com.snc.process_flow.v2.exec.OpInstructionExecutor.execute(OpInstructionExecutor.java:27)
at com.snc.process_flow.v2.exec.OpInstructionExecutor.execute(OpInstructionExecutor.java:16)
at com.snc.process_flow.v2.exec.EngineV2.executeInstructions(EngineV2.java:182)
at com.snc.process_flow.v2.exec.EngineV2.run(EngineV2.java:106)
at com.snc.process_flow.v2.exec.EngineRunner.lambda$run$0(EngineRunner.java:28)
at com.snc.process_flow.v2.exec.enviroment.execution.ExecutionScopeRunner.run(ExecutionScopeRunner.java:37)
at com.snc.process_flow.v2.exec.EngineRunner.run(EngineRunner.java:28)
at com.snc.process_flow.engine.EngineV2Adapter.runWithExecutionResult(EngineV2Adapter.java:253)
at com.snc.process_flow.engine.ProcessAutomation.runWithExecutionResult(ProcessAutomation.java:109)
at com.snc.process_flow.engine.ProcessAutomation.run(ProcessAutomation.java:70)
at com.snc.process_flow.engine.GlideProcessAutomation.runSync(GlideProcessAutomation.java:234)
at com.snc.process_flow.engine.GlideProcessAutomation.runWithDomain(GlideProcessAutomation.java:380)
at com.snc.process_flow.engine.GlideProcessAutomation.lambda$runAsUserSync$1(GlideProcessAutomation.java:345)
at com.snc.process_flow.engine.PFSessionClone.run(PFSessionClone.java:71)
at com.snc.process_flow.engine.GlidePFSession.runPlanAsUserSession(GlidePFSession.java:42)
at com.snc.process_flow.engine.GlideProcessAutomation.runAsUserSync(GlideProcessAutomation.java:343)
at com.snc.process_flow.engine.GlideProcessAutomation.messageFlow(GlideProcessAutomation.java:440)
at com.snc.process_flow.engine.GlideProcessAutomation.messageFlow(GlideProcessAutomation.java:404)
at com.snc.process_flow.approvals.ApprovalHelper.notifyApprovalAction(ApprovalHelper.java:623)
at com.glide.plan.runners.scriptable.ScriptableFlowAPI.jsStaticFunction_notifyApprovalAction(ScriptableFlowAPI.java:292)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:236)
at org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:674)
at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:603)
at org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2988)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1928)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1112)
at org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:161)
at com.glide.caller.gen.sys_script_b52c8c93872030102769a1bb36cb0be1_script.call(Unknown Source)
at com.glide.script.ScriptCaller.call(ScriptCaller.java:22)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:160)
at org.mozilla.javascript.ScriptRuntime.doCall2(ScriptRuntime.java:3089)
at org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2998)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1928)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1112)
at org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:161)
at com.glide.caller.gen.sys_script_b52c8c93872030102769a1bb36cb0be1_script.call(Unknown Source)
at com.glide.script.ScriptCaller.call(ScriptCaller.java:22)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:160)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:702)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:4412)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:174)
at com.glide.script.ScriptCompiler.executeAndPublishMetric(ScriptCompiler.java:77)
at com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:439)
at com.glide.script.ScriptEvaluator.evaluate(ScriptEvaluator.java:219)
at com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:375)
at com.glide.script.BusinessRule.runScript(BusinessRule.java:468)
at com.glide.script.BusinessRule.runSyncBusinessRule(BusinessRule.java:336)
at com.glide.script.BusinessRule.runBusinessRule(BusinessRule.java:223)
at com.glide.script.BusinessRule.run(BusinessRule.java:199)
at com.glide.script.GlideRecordBusinessRules.run(GlideRecordBusinessRules.java:248)
at com.glide.script.GlideRecord.runScripts(GlideRecord.java:1510)
at com.glide.script.GlideRecord.runScriptsAndEngines(GlideRecord.java:1451)
at com.glide.script.GlideRecord.postChange(GlideRecord.java:5504)
at com.glide.script.GlideRecord.postUpdate(GlideRecord.java:5477)
at com.glide.script.GlideRecord.updateWithoutResettingOperation(GlideRecord.java:5002)
at com.glide.script.GlideRecord.update(GlideRecord.java:4866)
at com.glide.script.GlideRecord.update(GlideRecord.java:4785)
at com.glide.ui_list_edit.ListEditSaver.update(ListEditSaver.java:204)
at com.glide.ui_list_edit.ListEditSaver.save(ListEditSaver.java:92)
at com.glide.ui_list_edit.ListEditSet.process(ListEditSet.java:32)
at com.glide.ui_list_edit.AJAXListEdit.process(AJAXListEdit.java:43)
at com.glide.processors.XMLHttpProcessor.processJavaAJAX(XMLHttpProcessor.java:168)
at com.glide.processors.XMLHttpProcessor.process(XMLHttpProcessor.java:121)
at com.glide.processors.AProcessor.runProcessor(AProcessor.java:779)
at com.glide.processors.AProcessor.processTransaction(AProcessor.java:326)
at com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:187)
at com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:175)
at com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:58)
at com.glide.sys.Transaction.run(Transaction.java:2803)
at com.glide.ui.HTTPTransaction.run(HTTPTransaction.java:35)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)

 

And then..

 

Encountered error executing instruction: ActionErrorEvalInstruction{id=250, conditions=[], statusKey=c52o.__action_status__, dontTreatAsErrorKey=c52o.__dont_treat_as_error__}, errorMessage:Error: "fd_data" is not defined.,Detail: "fd_data" is not defined., errorCode:1

 

I don’t know what the first error means and I don’t know why it’s saying that fd_data isn’t defined when it works perfectly when I use the references other ways.

 

I am quite stumped and any help would be most appreciated.

1 ACCEPTED SOLUTION

IDewar
Tera Expert

Just in case someone finds this post, I found the solution. 

 

Instead of adding the reference into the string script (which as mentioned works 90% of the time) you have to create a variable with the reference in it then link to that variable. The Script would then be:

var supportFlowImg = fd_data.trigger.current.u_support_flow_diagram.toString()

 

 

 

<tr style="height: 37.3125px;">\
<td style="width: 193.219px; background-color: rgb(194, 224, 244); height: 37.3125px;"><span style="font-family: verdana, geneva;"><strong><span style="font-size: 10pt;">3.0 Support Flow Diagram</span></strong></span></td>\
<td style="width: 850.657px; height: 37.3125px;" colspan="3"><img src="https://hestest.service-now.com/' + supportFlowImg + '.iix" alt="Support Flow Diagram" width="800"></td>\
</tr>\​

 

I don't know why this makes a difference but it does. This is also true of creating url links too. 

View solution in original post

1 REPLY 1

IDewar
Tera Expert

Just in case someone finds this post, I found the solution. 

 

Instead of adding the reference into the string script (which as mentioned works 90% of the time) you have to create a variable with the reference in it then link to that variable. The Script would then be:

var supportFlowImg = fd_data.trigger.current.u_support_flow_diagram.toString()

 

 

 

<tr style="height: 37.3125px;">\
<td style="width: 193.219px; background-color: rgb(194, 224, 244); height: 37.3125px;"><span style="font-family: verdana, geneva;"><strong><span style="font-size: 10pt;">3.0 Support Flow Diagram</span></strong></span></td>\
<td style="width: 850.657px; height: 37.3125px;" colspan="3"><img src="https://hestest.service-now.com/' + supportFlowImg + '.iix" alt="Support Flow Diagram" width="800"></td>\
</tr>\​

 

I don't know why this makes a difference but it does. This is also true of creating url links too.