Transform map field script code explanation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2023 08:39 PM
Hi All,
Could you please explain line by line code for below which is written in transform map field script and choice action is --> ignore and source and target fields are mapped as expected.
var grChoice = new GlideRecord('u_il_rel_choice');
grChoice.addQuery('u_na_choice_name', source.u_select_ds_options_);
grChoice.addQuery('u_na_de_class_name.u_na_de_class_name', source.u_select_list_class_);
var grDomain = grChoice.addQuery('sys_domain.name', source.u_domain);
grDomain.addOrCondition('sys_domain', 'global');
grChoice.query();
if (grChoice.next()) {
return grChoice.sys_id;
}
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2023 09:57 PM
Hi @Mohamed_009 ,
var grChoice = new GlideRecord('u_il_rel_choice');
grChoice.addQuery('u_na_choice_name', source.u_select_ds_options_);
grChoice.addQuery('u_na_de_class_name.u_na_de_class_name', source.u_select_list_class_);
var grDomain = grChoice.addQuery('sys_domain.name', source.u_domain);
grDomain.addOrCondition('sys_domain', 'global');
grChoice.query();
if (grChoice.next()) {
return grChoice.sys_id;
}
The above code is querying "u_il_rel_choice" table (Line 1), based on the values retrieved in transform map data source (may be a database or excel), and querying the table on fields,
- u_na_choice_name,
- u_na_de_class_name.u_na_de_class_name [ This field is dot walked field, means u_na_de_class_name is a reference field in u_il_rel_choice table and u_na_de_class_name is a field on referenced table.
- sys_domain.name [This is also dot waled field] - Querying the domain of the record
- grDomain.addOrCondition('sys_domain', 'global');
3 & 4 fields are like OR condition the record should be either in a Specific domain or Global domain.
Finally this code is returning the sys_id of the the record found based on the query parameters.
If the code is not working, try changing the line grDomain.addOrCondition('sys_domain', 'global'); to grDomain.addOrCondition('sys_domain.name', 'global');
Thanks,
Anvesh
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2023 11:46 PM
@Mohamed_009
var grChoice = new GlideRecord('u_il_rel_choice'); - you want data to retrieve from this custom table
grChoice.addQuery('u_na_choice_name', source.u_select_ds_options_); - querying the fields
grChoice.addQuery('u_na_de_class_name.u_na_de_class_name', source.u_select_list_class_); - dot walk the field and querying this field from the table u_il_rel_choice.
var grDomain = grChoice.addQuery('sys_domain.name', source.u_domain); - dot walking the domain field
grDomain.addOrCondition('sys_domain', 'global'); - used or condition record will be from global or a particular domain.
grChoice.query(); - query the table
if (grChoice.next()) {
return grChoice.sys_id;
} - if condition will match with the query and will retrieve some record you will get the sys id of the record.
Please mark my answer correct and helpful if it helps you.