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

@Brad Bowman  changed it to Display, but no luck. 😕 I think im still missing something here..

Darn.  So are you seeing the 'true' infoMessage displayed when it should and the 'false' infoMessage displayed when it should? Since your client script is onSubmit, the Service task field is blank when you submit the form, but then does change to 'Yes' when it should?  With the Service task field blank when you submit a form where the 'true' message is displayed, the Service task field remains blank?  If the service task field is a Choice type, did you confirm that the value of the other choice is exactly 'no' - case-sensitive and no extra space at the end? 

Nope. Not seeing any of the info message. But, I can confirm that the logic to change the "Service Task" field to "Yes" is working, but not in changing to No.

Also, I can confirm that the Service task" field choices are correct.

SabrinaSalazar_0-1675864043669.png

 

On the other hand, I noticed that  my field type is actually String so I changed it to Choice.

Now I am seeing the "false"  info message

SabrinaSalazar_0-1675864536140.png

 

But still, the logic to changing "No" has no luck..

@Brad Bowman  

 

Thanks but just wondering why it didn't work. Here's my updated CS and BR. Hoping you can guide me on this? Thanks 

 

Client Script: vtb_task

function onSubmit() {
//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');
}
}

 

 

Business rule:

Table: vtb_task

Before - Insert , Update

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