Should I be concerned with this error only in Tokyo instances

Ian Mildon
Tera Guru

We are running a little behind the curve and our Prod instance has not yet been upgraded to Tokyo (or Utah) but that fix is coming fast.

 

Anyway, my issue is that I was fixing a syntax error in a Script Include that is now displaying another "error" flag, but only on our two sub-prod instances that are on Tokyo. The error states "JSON is not a function" and this is the script which, BTW, continues to work despite the error.

var AttachKB = Class.create();
AttachKB.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getAttachedKB : function(){
		
        var wNotes = this.getParameter('sysparm_wNotes');
        var kbNum = this.getParameter('sysparm_kbNum');

        var gr = new GlideRecord('kb_knowledge');
        gr.addQuery('sys_id', kbNum); //need to match the kb article	
		gr.addQuery('u_customer_facing', true);
		gr.query();
		if (gr.hasNext()) {
			if (wNotes.includes('[code]<a title=')) { //* to fix "unexpected constant condition" error
				var obj = {comments: wNotes};
				var data = new JSON().encode(obj); //! this is giving an error "JSON is not a function" but the script works
				return data;
            }
		}
	},
	
	type: 'AttachKB'
});

I don't like the fact that I'm fixing one issue and now seeing another, and unsure if I should just ignore it, seeing as it still works, or if this is now a "ticking" issue that will break sometime in the future.

 

Has anyone else seen this error, and/or should I be concerned?

1 ACCEPTED SOLUTION

Ian Mildon
Tera Guru

Overall your help worked and the script is now working but I do need to point out a minor issue with your second "fix".

 

Adding quotes to the wNotes part of the Obj had the effect of returning wNotes and not the expected value. Removing the quotes from this part returned the expected value.

 

So the final, and now fully working version is:

var AttachKB = Class.create();
AttachKB.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getAttachedKB : function(){
		
        var wNotes = this.getParameter('sysparm_wNotes');
        var kbNum = this.getParameter('sysparm_kbNum');

        var gr = new GlideRecord('kb_knowledge');
        gr.addQuery('sys_id', kbNum); //need to match the kb article	
		gr.addQuery('u_customer_facing', true);
		gr.query();
		if (gr.hasNext()) {
			if (wNotes.includes('[code]<a title=')) { //* to fix "unexpected constant condition" error
				var obj = {"comments": wNotes};
				var data = JSON.stringify(obj);
				return data;
			}
		}
	},
	
	type: 'AttachKB'
});

View solution in original post

5 REPLIES 5

Not a problem and glad for your help.

 

And if you're interested, the value is a KBA link inserted by the Attach function on the Incident table, which inserts to the Work Notes field. For KBA's that are customer facing, we want them to also be inserted into the Additional Comments field. This and an onChange Client Script handles the process.