- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2018 08:32 AM
There I have my solution which works and it returns the name, which is used in Portal side (to show for end-user).
Would like to
Script include:----------------------------------------------
var getApprover = Class.create();
getApprover.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUser: function() {
var appover = this.getParameter('sysparm_sapPath');
var sapMap = new GlideRecord('u_sap_service_mapping_rules');
if(sapMap.get(appover))
return sapMap.u_sap_path_approver.name; // I would like to get the NAME and sys_id values by one script include. Tried but no working? Can paste not-working solution below.
return '';
},
type: 'getApprover'
});
Script include:----------------------------------------------
Catalog client script:---------------------
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = new GlideAjax('getApprover');
gr.addParam('sysparm_name','getUser');
gr.addParam('sysparm_sapPath',g_form.getValue('sap_po_form_po_folder'));
gr.getXML(updateApprover);
function updateApprover(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
/*
g_form.setValue('sap_folder_approver', answer);
}
//Type appropriate comment here, and begin script below
Catalog client script:---------------------
Here is how I tried to fetch the data like JSON:
Catalog client script:---------------------
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = new GlideAjax('getApprover');
gr.addParam('sysparm_name','getUser');
gr.addParam('sysparm_sapPath',g_form.getValue('sap_po_form_po_folder'));
gr.getXML(updateApprover);
function updateApprover(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var data = JSON.parse(answer);
g_form.addInfoMessage(data);
alert(data); == This returns just 'object Object'
g_form.setValue('sap_folder_approver', data.name);
}
}
Catalog client script:---------------------
Script include:----------------------------------------------
var getApprover = Class.create();
getApprover.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUser: function() {
var appover = this.getParameter('sysparm_sapPath');
var sapMap = new GlideRecord('u_sap_service_mapping_rules');
if(sapMap.get(appover)) {
var json = new JSON();
var results = {
"sys_id": user.getValue("sys_id"),
"name": user.getValue("name")
};
return json.encode(results);
}
}
});
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2018 12:15 PM
Yes sorry, there was a mistake in my original answer. this approach would be better because it avoids an unnecessary dot-walk
results.sys_id = sapMap.getValue('u_sap_path_approver');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2018 09:05 AM
I like your thinking on this. I always return JSON from my GlideAJAX nowadays. I think it is so much easier to work with. here is my take on your scripts. Note this is untested, but should give you the idea for how to frame this.
Script Include
var getApprover = Class.create();
getApprover.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUser: function() {
var appover = this.getParameter('sysparm_sapPath');
var sapMap = new GlideRecord('u_sap_service_mapping_rules');
// set the defaults here, so you can return an object no matter what
var results = {
sys_id: "",
name: ""
};
if(sapMap.get(appover)) {
results.sys_id = sapMap.u_sap_path_approver.getValue();
results.name = sapMap.u_sap_path_approver.getDisplayValue();
}
// return the object here so you get something back
// even if approver not found
return JSON.stringify(results);
}
});
Client Script:
var gr = new GlideAjax('getApprover');
gr.addParam('sysparm_name', 'getUser');
gr.addParam('sysparm_sapPath', g_form.getValue('sap_po_form_po_folder'));
gr.getXMLAnswer(function (answer) {
var data = JSON.parse(answer);
console.log(data);
g_form.setValue('sap_folder_approver', data.sys_id, data.name);
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2018 11:56 AM
Hi Jon,
Thanks for the solution, it really worked and it really looked good, thanks.
My plan was to use the data.sys_id on setting approval task to approver. As the data.name is used to shown the approver for end-user (Single Line Text) -field.
As the "sap_po_form_po_folder" -field is reference field to sys_user -table.
My plan was something like this.
---
var SapApproval = new SapApprovalMatrix(); /// renamed the script include to be for informative 🙂
var approver = SapApprovalMatrix(current);
workflow.scratchpad.approver.push(approver.data.sys_id);
---
What would yours solution for this?
Appriciate your feedback, even idea how to do it effectively.
Br,
Jussi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2018 03:30 AM
Then, I dont get this as this returns nicely name but sys_id not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2018 10:31 AM
Here is the solution at least how figured it out:
results.sys_id = sapMap.u_sap_path_approver.sys_id.toString();