The CreatorCon Call for Content is officially open! Get started here.

How to dot walk from a parent request to child task in a workflow run script?

mohammedunwala
Giga Contributor

Hi everyone,

I have a run script in my workflow (which is running on the request) to update the value of a field in a 'store_database' table with the current value of the field that is sitting on a task within that request.

Script:

updateScript();

function updateScript() {

  var gr = new GlideRecord('x_rommi_branded_rs_store');

  gr.addQuery('sys_id', current.u_location_dealer_name);

  gr.query();

  while (gr.next()){

  gr.u_lease_expiry = current.parent.u_lease_expiry;

  gr.update();

  }

}

Of course, the above script is not working as my current field is sitting on the task table instead of request and my workflow is running on the request table. I am trying to dot walk from parent (request) to child (task) here so that I can get the value of that field. Any thoughts on where I am going wrong?

Thanks,

Mohammed

7 REPLIES 7

Chuck Tomasi
Tera Patron

If current is the request, what is current.parent? I'm thinking your single line



gr.u_lease_expiry = current.parent.u_lease_expiry;



should really be



gr.u_lease_expiry = current.u_lease_expiry;



if I understand your requirements correctly.


Hi Chuck,


I already tried:


gr.u_lease_expiry = current.u_lease_expiry;


But it didn't work as the lease expiry field is sitting on one of the task instead of the request.


In gr.u_lease_expiry = current.parent.u_lease_expiry;


I m trying to dot walk from parent to child but i also know that's not the right script.



I hope this helps understand my problem.


Hi Mohammed,



You need to query to get the child record. There is no way to dot-walk from a parent to child because it is a one-to-many relationship. It's like asking the database to "update the incident for my account" when I have hundreds of incidents on file. You need to be specific about which one and write the query to get it and modify that specific one.



In order to be of more help, I would need to know more about your data model you are dealing with (specific table names, field names, and which fields relate them.)


Hi Chuck,


ok that makes sense. Yes I can provide you with the details and would appreciate if you can help me with the script.



Source table (task): x_rommi_branded_rs_brs_lease_details


Source field (task form): u_lease_expiry


Target table (database): x_rommi_branded_rs_store


Target field (database form): u_lease_expiry


Workflow table (request): x_rommi_branded_rs_new_store_location_request


Run Script name: Update the record into store database table



Let me know if you need any help.



Regards,


Mohammed