Set field value if the related list has the current record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 08:20 PM
Hi team,
Would like to know how do we script/check whether the related list of the current record is not empty. See below screen shots for reference.
In the Private Task [vtb_task] form, the related list is "Visual Task Board Cards"
When we check the list of the "Visual Task Board Cards" [vtb_card] , you can see the PTASK record is in the "Task" field of "Visual Task Board Cards" [vtb_card]
The requirement is when the current PTASK is in the "Visual Task Board Cards" [vtb_card], the "Service Task" field in PTASK form will be set to "No"
Tried creating a business rule and client script but it seems to be NOT working.
Business Rule:
Table: vtb_card
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var vtask = new GlideRecord('vtb_task');
vtask.addQuery('sys_id', current.getUniqueValue());
vtask.query();
if (vtask.hasNext())
g_scratchpad.isParent = true;
else
g_scratchpad.isParent = false;
})(current, previous);
Client script:
Table: vtb_task
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_scratchpad.isParent) {
g_form.setValue('x_bmk_technology_s_u_service_task_1', 'no');
} else {
g_form.setValue('x_bmk_technology_s_u_service_task_1', 'yes');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 04:07 AM - edited 02-03-2023 04:08 AM
I re-created this in my PDI by adding a field to my vtb_task table. This table is in the Global scope, so when I added the field, the name was just u_service_task_1, not prefixed with my custom scope ID. I made my field a Choice type with the choices yes and no. Your Business Rule / Client Script combination doesn't make sense in that the (display, I assume) Business Rule is running on the card table, but the Client Script is onLoad of the task table - so which record are you displaying in hopes of updating the custom field? I'll assume you want this to happen when the Private Task record is displayed, so the script for the display Business Rule on the vtb_task table would look like this:
(function executeRule(current, previous /*null when async*/ ) {
var vcard = new GlideRecord('vtb_card');
vcard.addQuery('task', current.getUniqueValue());
vcard.query();
if (vcard.next()) {
g_scratchpad.isParent = true;
} else {
g_scratchpad.isParent = false;
}
})(current, previous);
then your onLoad Client Script is fine, depending on the custom field name - my setValue lines are just u_service_task_1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2023 05:55 PM
Hi @Brad Bowman thanks for this. The logic to make the Service Task field = Yes is working, but it doesn't make the field change to No.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 04:48 AM
There are a couple of things you can do to trouble-shoot this. The first is to temporarily add some logging lines to the Business Rule to confirm if/when it is running and the result of the GlideRecord:
(function executeRule(current, previous /*null when async*/ ) {
var vcard = new GlideRecord('vtb_card');
vcard.addQuery('task', current.getUniqueValue());
vcard.query();
if (vcard.next()) {
g_scratchpad.isParent = true;
gs.addInfoMessage('true')
} else {
g_scratchpad.isParent = false;
gs.addInfoMessage('false')
}
})(current, previous);
Once you confirm that viewing a Private Task Record in each test case gives the correct result from the Business Rule, check the value in the Client Script vs. the field value. In my case I created a Choice type field with the values 'yes' and 'no', but maybe yours is 'No' or 'no ' with an errant space at the end?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 05:35 PM
Thanks but Not sure where I went wrong. Here's my updated BR and CS. The "No" still not working tho. Hope you can guide me on this? Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 05:29 AM
Ah, so the Business Rule When to run needs to be 'display', not 'before'.