- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 03:32 AM
Hi,
We have client script and script include which I am using to calculate the risk.I getting the value from the weight table but I am unable to set the value to field.it is disappearing .
server script
Calculate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
calculate: function(){
var f=this.getParameter('sysparm_field');
gs.log('hello123'+f);
var g=new GlideRecord('u_weights');
g.addQuery('u_name',f);
g.query();
var count= 0;
while(g.next()){
count+=g.u_wieights;
}
return count;
},
Client script
function onSubmit() {
//Type appropriate comment here, and begin script below
//alert(arrFields);
var fields = g_form.getEditableFields();
//alert(fields);
var b =0;
//Getting the score of all selected checkbox in section G
for(var i=0;i<fields.length;i++){
var str = fields[i];
if(g_form.getValue(fields[i])=='true' && str.substring(0,3)=='u_g'){
alert('field'+str.substring(0,3));
//alert(fields[i]);
var bs=new GlideAjax('calculate');
bs.addParam('sysparm_name','calculate');
bs.addParam('sysparm_field',fields[i]);
bs.getXML(HelloWorldParse);
}
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
b=b + parseInt(answer);
alert('now1'+parseInt(answer)+"And Total: "+d);
g_form.setValue('risk',b);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 03:52 AM
I don't really understand the use case for setting a value of a field on the form based on other fields on the form. A before insert/update business rule will do the same thing.
You can make you glideajax synchronous with getXMLWait() but you make your users hang around while the client script completes. If you use a business rule they can be off about their other work whilst the BR runs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 03:36 AM
not sure if your setValue got executed because of previous line
'alert('now1'+parseInt(answer)+"And Total: "+d);'
where d is not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 03:39 AM
Also you may want to check if "Risk" is integer field or string field and parse it as per need before setting the value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 03:43 AM
This is because you are using asynchronous GlideAjax. At the time your call back function is called, form is already submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 03:52 AM
I don't really understand the use case for setting a value of a field on the form based on other fields on the form. A before insert/update business rule will do the same thing.
You can make you glideajax synchronous with getXMLWait() but you make your users hang around while the client script completes. If you use a business rule they can be off about their other work whilst the BR runs.