Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

onClick function in UI page

ryadavalli
Tera Expert

I have a UI page, I have a button, which upon click call the client script and pass the context sysapproval record to client scrim. How can I do that?

8 REPLIES 8

Not sure if I follow you but lets try 😃



if you got a url like: .....service-now.com/mypage.do?sysparm_id=42354334543m5n4352h2423



On the UI page you can do something like



<g:evaluate var="myvariable">


var sysparm_id = RP.getParameterValue("sysparm_id");


                    sysparm_id;


</g:evaluate>




Then you can throw that into a hidden input:


<input type="hidden" id="kb_article" name="kb_article" value="${myvariable}"/>




And from client script:



var article= gel("kb_article").value;




Sorry about not changing the names/variables to something clever 😃 To tired


HEy Goran,



Thanks for the help !


Actually I have 2 buttons on UI page (change form change tasks)


change task 1 - Button 1


change task 2 - Button 2



Upon click I want to get the change task 1 assignment when user clicks on the button 1 and change task 2 assignment grp when button 2


I have <td style="text-align:center"><button class="getAssgnGrp" onclick="myFunction('${current.sys_id}')"><img src="image.gif"></img></button></td>



Is this the correct way and how to get the value in client script



client script:


function myFunction(test){



    alert("Hello == "+test);


}


I think I got it. I was passing some wrong value.. Now I get the values.


Yea.. you can put it like that as well. Then you don't need the hidden input either.



Just so I understand. You got 2 buttons which would go too two different   tasks.



If I think I understand you, you can't use "current" as in other scripts.



I would have made the buttons like this:


<td style="text-align:center"><button class="getAssgnGrp" onclick="myFunction('${taskone.sys_id}')"><img src="image.gif"></img></button></td>


<td style="text-align:center"><button class="getAssgnGrp" onclick="myFunction('${tasktwo.sys_id}')"><img src="image.gif"></img></button></td>



Then above that code you need something simular to this:



<g:evaluate>


//Fetch task one


var taskone = new GlideRecord('change_request');


taskone.get('number','CHG002133');


</g:evaluate>



<g:evaluate>


//Fetch task two


var tasktwo = new GlideRecord('change_request');


tasktwo.get('number','CHG002134');


</g:evaluate>




Then the client script like you did.


The g:evaluate for you is abit more dynamic, but I think you understand what I'm trying to "say" 😃