How to add if condition in GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 02:48 AM
I have two tables chromebook and computer table having a field location which is referring to Location table.
I have to update the location value from chromebook table to computer table. The scenario is as follows -
1. If location given in Chromebook table matches with any location of location table then update as it is in Computer table.
2. Suppose the location in Chromebook table is Espoo 23 and the first word i.e. Espoo matches with any record in location table then update the 1st word of the location in the Computer table.
3. If no records is matching with the locations in the Location table, then update the location field with a dummy value in Computer table.
I have written the BR for this as follows -
var locFirstName = current.u_location;
var locFirstName1 = locFirstName.split(' ')[0];
var locName = "";
var loc = new GlideRecord('cmn_location');
loc.addEncodedQuery("full_name="+locFirstName + "full_nameSTARTSWITH" + locFirstName1);
loc.query();
while(loc.next()){
if(loc.full_name == locFirstName){
locName=loc.sys_id;
}else if((loc.full_name).indexOf(locFirstName1)!=-1){
locName=loc.sys_id;
}
}
if (locName == "") {
locName ="d2ca78121b5f5d5014811023b24bcb56";
}
It is not working for r the 2nd condition, i.e. to take the 1st word of the Location.
Where am I wrong in my code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 03:04 AM - edited 04-24-2023 03:05 AM
Hi,
I think that your encoded query is not OK. You have not operator neither AND (^) nor (^NQ). It will retrieve all table records
var locFirstName = current.u_location;
var locFirstName1 = locFirstName.split(' ')[0];
var locName = "";
var loc = new GlideRecord('cmn_location');
loc.addEncodedQuery("full_name="+locFirstName + "full_nameSTARTSWITH" + locFirstName1);
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 03:08 AM
What will be the encoded query?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 03:51 AM - edited 04-24-2023 04:03 AM