Issues calling Script Include from Client Sciprt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 03:25 PM
Hi All,
I am trying to write a Client Script to copy the benefit plan name same as the demand name. for this, using a client script and a script include (to get the demand details).
The Client Script is unable to call the Script include for some reasons which i am unable to understand.
The Script Include is created with option 'Client Callable' enabled.
This is assessable from 'All application scope' and there is access.
Can someone spot the issue here?
Client Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 03:58 PM
There's likely not an error calling the Script Include, rather the execution/completion of it. You can confirm this by adding alerts to the client script and gs.info or gs.addInfoMessage lines to the SI to confirm that it is running, the value that is passed in from the client, and how far the script gets. In this case, sysparm_initId and taskSysId are likely unknown/null. I don't think g_form.getValue('benefit_plan.task')) is valid. If the alert is returning the correct sys_id, then OK. In the Script Include, the alternate assignment of taskSysId is invalid as you are supplying the Number field from a Demand, not the sys_id field. The formatting/syntax of the SI is also off. You always want to return something to the client. I would recommend:
var CarbonBenefitNameAjax = Class.create();
CarbonBenefitNameAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getName: function() {
gs.addInfoMessage('SI running');
var answer = '';
var taskSysId = this.getParameter('sysparm_initId');
gs.addInfoMessage('benefit plan sys_id = ' + taskSysId;
var grtask = new GlideRecord('dmn_demand');
if (grtask.get(taskSysId) {
//answer = grtask.short_description;
answer = 'Hello from SI';
}
return answer;
},
type: 'CarbonBenefitNameAjax'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 02:19 AM
Thanks a lot for the suggestion.
There was an issue with the name of the function used. -getName.
Changing it to something else, worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 04:27 AM
That makes sense. I've seen a few people have trouble with this. It seems like they should be able to warn in the script editor when a reserved word is used as a function name.