How to populate value in a field on approval table from workflow?

thirumala2
Tera Guru

Hi ,

We have a requirement of populating value from workflow to a given field on approval table for managed docs .

find_real_file.png

From the below workflow run script :

find_real_file.png

@shloke04 can u help ?

 

1 ACCEPTED SOLUTION

By mistake I have put a quotes while setting the value. You need to remove that:

Modified script below:

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id',current.sys_id);
gr.query();
while(gr.next()){
gr.FIELDNAME = current.number.toString(); // Replace "FIELDNAME " with the one where you want to set on Approver table
gr.update();
}

Try now should work.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

36 REPLIES 36

Yeah now I see why it is not working for you. This is what I was trying to ask you from my post above that where is your workflow written and where are you generating your approvals.

Reason why it is not working is because the workflow is on "Document(dms_document) table and approvals are generating on Document revision table.

So you need to update your script as below:

var gr = new GlideRecord('dms_document_revision');
gr.addQuery('sys_id',current.sys_id);
gr.query();
while(gr.next()){
updateApprovals(gr.sys_id,gr.document.number);
}

function updateApprovals(documentRevisionID,documentNumber){
var gr1 = new GlideRecord('sysapproval_approver');
gr1.addQuery('document_id',documentRevisionID);
gr1.addQuery('source_table','dms_document_revision');
gr1.query();
while(gr1.next()){
gr1.u_managed_document = documentNumber; // Replace "u_managed_document" with your field Name present in Approval table
gr1.update();
}
}

This should work for you.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

find_real_file.png

Wf is on revision table only.

Okay. Thanks for confirming.

Just update your script as below:

var getDocument = current.document.number.toString(); // This will give you the Document Number as you need
var gr = new GlideRecord('sysapproval_approver);
gr.addQuery('document_id',current.sys_id);
gr.query();
while(gr.next()){
gr.u_manage_document = getDocument; // Replace "u_manage_document" with the field on Approval table where you need to update Document Number
gr.update();
}

I have tested this in my PDI and works fine for me.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi @shloke04 ,

I did copied and updated the script its still not working for me .Anything I missed .

var gr = new GlideRecord('sysapproval_approver

I added the inverted comma still the same .

Can you share the complete code and also a screenshot of the activity where you are trying to add this code.

The code should work which I have shared, but would ask you to share the screenshot of the code and the activity as well just to make sure you are putting it in right place or not.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke