How to change a string value on one table and set a string value on another table?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 06:14 PM
Hello,
I am wondering if anyone has written a script include to change a string value on one table and set a string value on another table?
scenario:
I have two values; barcode description & inventory description.
These both need to be the same and if one is changed, the other needs to replicate.
Reason:
We create barcodes to be able to print shelf labels for the inventory item.
only thing is once it is converted to a shelf label (HTML) any barcode description with an '&' symbol is failing as it is seeing it as an 'amps&'.
I have found multiple articles to do something similar but they all seem to using reference fields and not string.
any assistance would be extremely appreciated.
i am self taught scripter so i am a novice.
Phil.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 11:04 PM
Hi Phil O'shea,
Try using business rule on your custom table in which barcode description field is there.
in that script glide another table in which changes needs to be reflected.
Script:
var gr= new GlideRecord('table name');
gr.addQuery('sys_id',current.sys_id); //if same record is present in another table
gr.initialise(); // use this, If record is not present.
gr.inventory_description = current.barcode_description;
gr.insert(); //use this, If record is not present.
gr.update();//if same record is present in another table
Please Hit like, Helpful or Correct depending on the impact of the response
Regards,
Ashvini Kadus

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2018 05:31 PM
Hi Mate,
Firstly, thank you for your time.
secondly, so i understand this correctly:
var gr= new GlideRecord('u_alm_inventory'); // this is the table i want to glide to?
gr.addQuery('eac61524699c29008d1a759c925613ff',current.sys_id); // the sysID of the variable in the Record/Form of the table i have glided to?
gr.initialise(); // use this, If record is not present.
gr.inventory_description = current.barcode_description; // these are the variables on both tables?
(unfortunately, whom ever built this originally called the variable value the same name.)
gr.insert(); //use this, If record is not present.
gr.update();//if same record is present in another table
I have renamed the display name on the barcode table to barcode description but the value is still called u_inventory_description.
could i define them by display name?
eg: gr.setDisplayName ('inventory description') = current.getDisplayName ('barcode description');
Thanks again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2018 05:17 AM
Hi Phil,
I am assuming the following scenario,
- There are two table. One table has barcode description field and second table has inventory description field.
- When barcode description field value change on first table then same value should replicate/store in inventory description field of second table and vice versa.
- I am assuming there must be any unique field (like number or ID etc) on both table to identify each record.
Solution as per above scenario:
- Create business rule -> Before insert update.
// Run the script login only if barcode description field value change.
In Advanced tab --> Condition field --> current.barcode_description != previous.barcode_description
Script:
var unqNum = current.number;//Assuming this number is unique field and present in second table too.
var gr = new GlideRecord('second table');
gr.addQuery('number', unqNum);
gr.query();
if(gr.next())
{
gr.inventory_description = current.barcode_description;
gr.update();
}
Write same kind of business rule on second form as well to update barcode description field if inventory description field value change.
Thanks,
Nitin Tongrao