- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2016 07:50 AM
Given a sys_id, how do we find to which record the sys_id belongs to?
Solved! Go to Solution.
- Labels:
-
Upgrades and Patches

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2016 08:04 AM
You COULD write a script that goes through sys_db_object and checks each table to see if it can find the record. With over 2,000 tables in a default Helsinki instance, this could take a while. The *untested* script might look something like this:
var mySysId = 'xxxxxxxxxxxxxxxxxxxxx'; // put in your sys_id here
var table = new GlideRecord('sys_db_object');
table.query();
while (table.next()) {
var gr = new GlideRecord(table.getValue('name'));
if (gr.get(mySysId)) {
gs.log('it looks like it came from ' + gr.getValue('label'));
break;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 10:29 PM
Hi Chuck,
In fact, I am doing something similar but the issue is:
I have a table abc .. and I have my record this table.
And I want to find this record in 'abc' table(gliderecord here) and then insert this record into some other 'xyz' table based on the sys_id of the record (gliderecord here as well).
And I am performing this action on some other SOURCE table.
Can you please help me to accomplish this, I don't want to hard code anything.
Thanks
Jyo

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 05:38 AM
Hi Jyo,
When would you like to copy the contents of the abc record to xyz table? Is it when abc is saved? Changes a particular field (e.g. state) to a particular value? When a UI action/button is clicked?
Can you clarify what you mean by this statement?
And I am performing this action on some other SOURCE table.
Perhaps if you walk me through the scenario of what happens to each record and in what order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 04:30 PM
Thanks a ton for your time!
Here is the detail:
So, what I am trying to do is...
I have a record entry in abc table (say with some fields like ID, Values, Quatity etc) kind of a data entry stored in there, we have an application where in these abc and xyz tables are the child of the SOURCE table which is the parent table.
So, whenever a stage changes say for example 'Project in Progress' then that record entry should be inserted into the xyz table only once. From once I mean no duplicate entries are allowed.
And apparently both abc and xyz tables have same fields but with different names.
And from my statement below, I meant that I am writing a business rule on this table because my stage condition is on this table:
And I am performing this action on some other SOURCE table.
I hope it helps!
Regards
Jyo

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 04:35 PM
Can you share the scripts you are using now to do this? It should be a simple matter of an AFTER business rule to check if the state has been met. If you have the sys_id of the record, then you can do something like this:
var abc = new GlideRecord('abc');
abc.id = 'SOME ID';
abc.quantity = SOME_QUANTITY;
if (abc.get('SYS_ID_OF_ABC_RECORD')) {
abc.update(); // update existing record
} else {
abc.insert(); // create new record
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 04:51 PM
Something like this:
var mID = new GlideRecord('abc');
mID.addQuery('sys_id', 'f362eefc6f3562806ca1da55eb3ee49c');
mID.query();
if (abc.get('f362eefc6f3562806ca1da55eb3ee49c')) {
var nonAPLrec = new GlideRecord('u_bom_non_apl');
nonAPLrec.initialize();
nonAPLrec.u_sl1 = mID.sys_id ;
nonAPLrec.u_quoted_quantity_uom_value=mID.u_quoted_quantity_uom;
nonAPLrec.u_description = mID.u_bom_non_apl_description ;
nonAPLrec.u_material_id = mID.u_material_id;
nonAPLrec.u_qty = mID.u_bom_non_apl_qty ;
nonAPLrec.u_cost_type = mID.u_cost_type ;
nonAPLrec.u_ext_price = mID.u_customer_price;
nonAPLrec.u_price = mID.u_price;
nonAPLrec.u_billable = mID.u_billable;
nonAPLrec.insert();
}