Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Update currency field by GlideRecord

Gaetano De Mitr
ServiceNow Employee
ServiceNow Employee

Hi guys,

Can I update currency field into table?

How can I update currency field by fix script using GlideRecord?

I'm using this script but not working it :

var gr = new GlideRecord ('alm_asset');

gr.addQuery('u_number','IN','ASSETNUMBER');

gr.query();

while ( gr.next()){

  gr.setValue('salvage_value','EUR;3.00'); // no update field ( value is: EUR 0,00 )

  gr.update();

}

Regards,

2 REPLIES 2

Gaurav Bajaj
Mega Sage

Hi,



Please try like below,


it works for me



gr.salvage_value='EUR;3';



Also, if this doesn't work out, please add some logs and check, I think it's not going into while loop at all ASSETNUMBER is in quotes.





var gr = new GlideRecord ('alm_asset');


gr.addQuery('u_number','IN','ASSETNUMBER');


gr.query();


while ( gr.next()){


  gr.setValue('salvage_value','EUR;3.00'); // no update field ( value is: EUR 0,00 )


  gr.update();


}




Thanks


Gaurav


ColeM
Kilo Sage

I resolved this issue by using the String() method around the currency value.  In my example resourceRate is a variable set earlier in my script. I'm not sure if your issue is the same considering you are already hardcoding a string.  My example..

 

            var resourcePlanGr = new GlideRecord('sn_plng_att_core_resource_assignment');
            resourcePlanGr.initialize();
            resourcePlanGr.task = demand;
            resourcePlanGr.assignment_type = assignmentType;
            resourcePlanGr.user_resource = userResource;
            resourcePlanGr.group_resource = groupResource;
            resourcePlanGr.role = role;
            resourcePlanGr.skill = skill;
            resourcePlanGr.effort_type = effortType;
            resourcePlanGr.effort = effort;
            resourcePlanGr.start_date = startDate;
            resourcePlanGr.end_date = endDate;
            resourcePlanGr.resource_status = resourceStatus;
            resourcePlanGr.rate_override = rateOverride;
            resourcePlanGr.resource_rate = String(resourceRate);   // NOTE: use of String() function 
            resourcePlanGr.insert();
        }