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 12:35 AM
@ss123 try this
(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();
g_scratchpad.isParent = vtask.hasNext();
})(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');
}
}
Thanks
Bharath
Bharath Chintala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2023 05:57 PM
@BharathChintala the script is not working when I tried it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 01:12 AM
onLoad client script will just set value in browser level. it won't save in database until user click save after opening page.
You have to go with different approach like
Write After BR on vtb_card table
on insert
conditions task.service_task is false// select conditions correctly as per your system
In Advanced
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var vtask = new GlideRecord('vtb_task'); //vtb_card table
vtask.get(current.task); //replace TASK with proper task field name
vtask.service_task = Yes;// set proer field and proper back end value if its check box then = true, if it is deropdown with yes or no then check value of yes in choice table and set = value;
vtask.update();
})(current, previous);
Bharath Chintala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 01:09 AM
Hi @ss123 ,
Business Rule
Table - vtb_task
Script :
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var vtask = new GlideRecord('vtb_card'); //vtb_card table
vtask.addQuery('TASK', current.getUniqueValue()); //replace TASK with proper task field name
vtask.query();
if (vtask.hasNext())
g_scratchpad.isParent = true;
else
g_scratchpad.isParent = false;
})(current, previous);