Set field value if the related list has the current record

ss123
Tera Contributor

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"

SabrinaSalazar_0-1675397477085.png

 

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]

 

SabrinaSalazar_1-1675397696613.png

 

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"

 

SabrinaSalazar_2-1675397817064.png

 

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');
}
}

 

14 REPLIES 14

BharathChintala
Mega Sage

@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

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

@BharathChintala the script is not working when I tried it.

@ss123 

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);

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Anup Desai1
Mega Sage

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);