Display reference field value into string fields

Kishore8
Kilo Guru

My script is not working:

var one = current.u_group.getDisplayValue();

var gr=new GlideRecord('sysapproval_approver');

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

gr.query();

if(gr.next())

{

gr.u_kb_group=one;

gr.update();

}

find_real_file.png

25 REPLIES 25

find_real_file.png




find_real_file.png


D Kishore,



In your screenshots I see you referencing the "approval for" column, but that is for only task related tables, if I recall. The other issue would be that document_id is a sys_id, and works together with a table specification.



Instead, try adding a condition in your business rule where the "Source table" field is "kb_knowledge" (a string). If that condition matches, you can then proceed to query for the knowledge record in question to retrieve it's group.



Below is a screenshot of a quick proof of concept business rule (running on the Approval table):


approvalBusinessRule.PNG



Then, I would use a script like below:



(function executeRule(current, previous /*null when async*/) {


        var getGroup = new GlideRecord('kb_knowledge');


        getGroup.addQuery('sys_id',current.document_id);


        getGroup.query();


        if (getGroup.next()){


                  current.u_kb_group= getGroup.u_group.getDisplayValue();


        }


})(current, previous);



I would be curious about the requirements, however. What exactly are you trying to accomplish by referencing the group in the approval record? There may be a less intrusive way to accomplish your requirement.


Hi Dylan,




First when i select Group in KB record, that Group name should be display in KB Approver     u_kb_group filed   .



as per your script you have taken Table:sysapprover_approvar   is it works??



I means when we update/insert KB record then KB record Group name should be display in Approver record   u_kb_group field


D Kishore,



The business rule I posted a screenshot is on the Approval table. That way, whenever an approval is added for a knowledge article, it will place the group name in the approval. In my example, I was making the assumption that the group field is specified before an approval record is inserted.



I did a couple tests, and my example worked, although of course you should conduct your own testing as well.


Hi Dylan,



here we are taking Group name before crate Approver in KB record



first we are filling KB record with short description, Group name , Category once we submit the form then after only Approvers will created.