Getting column value from user table using GlideRecord

AGK
Giga Contributor

Hi,

I am trying to get a column value from a table which I created, u_my_usertable, in SN workflow script task.

I am new to SN & scripting, I may be doing silly mistake.

u_fileid is a column in my u_my_usertable table.

Here is my code.

var wfname = workflow.name();

var gr = new GlideRecord('u_my_usertable');
gr.addQuery('sys_id',current.sys_id);

gr.query();
var fileid = gr.getDisplayvalue('u_fileid');

var loggedMessage = workflow.info(wfname  + " WF has started  with FileId = " + gr.getDisplayvalue('u_fileid') + " , SecondTry = " + fileid );

my Output

undefinedWF has started with FileId = , SecondTry= null

Can someone please help ?

 

Thanks,

1 ACCEPTED SOLUTION

AGK
Giga Contributor

I changed the code like below and it is working now, but still workflow.name() is not working for me so I changed my requirement.

I don't know why I was making my code complicated earlier. learning through mistakes :-). Thanks for your help. 

var loggedMessage = workflow.info("Workflow instance  " +current.sys_id + " has started  with FileId " + current.u_fileid );

View solution in original post

4 REPLIES 4

Prateek kumar
Mega Sage

var wfname = workflow.name();

var gr = new GlideRecord('u_my_usertable');
gr.addQuery('sys_id',current.sys_id);

gr.query();

if(gr.next()){
var fileid = gr.getDisplayvalue('u_fileid');

var loggedMessage = workflow.info(wfname  + " WF has started  with FileId = " + gr.getDisplayvalue('u_fileid') + " , SecondTry = " + fileid );

}


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Can you confirm for below as this is something where the issues is lying.

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

what is the current table? Also, make sure getDisplayvalue() is getDisplayValue()

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

AGK
Giga Contributor

I changed the code like below and it is working now, but still workflow.name() is not working for me so I changed my requirement.

I don't know why I was making my code complicated earlier. learning through mistakes :-). Thanks for your help. 

var loggedMessage = workflow.info("Workflow instance  " +current.sys_id + " has started  with FileId " + current.u_fileid );

DirkRedeker
Mega Sage
Hi Every time, you open a query, you need to use gr.next() to move to the first record, if there is one. Just running gr.query() will not open the first record. You can do like... if (gr.next()) { Do you record stuff } Hope that is helpful. Let me know, by marking my answer as correct and helpful, please. BR Dirk