Skip to main content

Service Portal widgets: pass stuff from html to client, server to html, etc

Server:

data.closedIssuesList = []; var grIncsClosed= new GlideRecord('incident'); grIncsClosed.addInactiveQuery(); grIncsClosed.addQuery(sQuery); grIncsClosed.orderByDesc('closed_at'); grIncsClosed.setLimit(iLimit); grIncsClosed.query(); iLimit=grIncsClosed.getRowCount();//--uncomment if want to limit to initial iLimit value while (grIncsClosed.next()){ var object_c = {}; object_c.number=grIncsClosed.number+""; object_c.sys_id=grIncsClosed.sys_id+""; object_c.short_description=grIncsClosed.short_description+""; object_c.sys_created_on=grIncsClosed.sys_created_on+""; object_c.sys_updated_on=grIncsClosed.sys_updated_on+""; object_c.assigned_to=grIncsClosed.assigned_to+""; data.closedIssuesList.push(object_c); //gs.addInfoMessage(sMsgPadder + object_c.number); }

HTML:

<div ng-repeat="closedTicket in ::data.closedIssuesList" > <div class="panel-body b-b result-item" style="background-color:#F2FBFE"> <a href="?id=form&sys_id={{closedTicket.sys_id}}&table=incident"><span class="mi-sd">{{closedTicket.short_description}}</span></a><br/> <span class="mi-fi">Issue Number: {{closedTicket.number}}</span> <span class="mi-fi">Created: {{closedTicket.sys_created_on}}</span> <span class="mi-fi">Updated: {{closedTicket.sys_updated_on}}</span> <button class="btn btn-default" style="float: right;background-color:#145896;color:#F2FBFE;font-size:14px" ng-click="mi_viewRecord(${closedTicket.sys_id})">View issue</button> </div> </div>






==================================


Server / HTML:

<button ng-click="mi_viewRecord(${closedTicket.sys_id})" >View issue</button>

Client controller:

function($scope)
{
$scope.mi_viewRecord = function (issueSYSID){ var sLink="?id=form&sys_id="+issueSYSID+"&table=incident"; //alert(sLink); window.open(sLink, '_self'); } }





==================================

HTML: 

<div id="mi-closed-tickets" style="display:none" ng-model = "c.closedList"> <!-- ... --> </div>



<button id="mi-button-closed" class="btn btn-default" ng-click="mi_showClosed()">Closed Issues</button>

Client controller:

$scope.mi_showClosed = function() { c.resultsList='My closed issues'; document.getElementById("mi-closed-tickets").style.display="block"; document.getElementById("mi-open-tickets").style.display="none"; }




or use:

angular.element($('#tbl_name')).val()

or 

$("mi-open-tickets").style.display="none";

==================================


Comments

Popular posts from this blog

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){

Get URL Parameter - server side script (portal or classic UI)

Classic UI : var sURL_editparam = gs . action . getGlideURI (). getMap (). get ( ' sysparm_aparameter ' ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); } Portal : var sURL_editparam = $sp . getParameter ( " sysparm_aparameter " ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); }