How to access Gliderecord data from portal widget HTML page

ytrottier
Tera Contributor

I have created a Service Portal widget where the Server script runs a GlideRecord query and returns 3 records.

I have a line in the Server script that returns the 3 records GR query :

data.info = gr

where gr is the gr object from the Server script.

In the widget HTML, I use the ng-repeat directive to loop through the 3 records like so :

<div ng-repeat="record in data.info" >

but that does not work.

Can someone explain the concepts and the HTML/Angular syntax to use in order to loop through the GR records and be able to access the records fields (something like {{record.sys_id}}, for example) ?

I have also seen examples like this {{::record.sys_id}}.

What is the difference between the syntax with and without the "::" ?

Any good reference documentation on this subject would also be useful.

Thanks.

4 REPLIES 4

Steven1
Tera Expert

SanjivMeher
Kilo Patron
Kilo Patron

Hi Yves,



For the records, you should push each gr record to data.info instead of using =.



So if you are using while loop to pull three records, you need to push them into data.info.



while (gr.next())


{


        data.info.push(gr);


}



the '::' is used to watch the value of that attribute. For example, If I want to show the users any changes to state field without user refreshing the form, I would put a ::. If I dont want to show the changes without a page refresh, I woudn't use ::



Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv.


I am not sure if you tried what you suggested but it does not work (at least for me).



In fact, what I have found is that what you need to do to pass data from the server script to the HTML template is to pass it as string values using the following method :


  1. Create an array under the data object, like here : data.info = [];
  2. Create an object, either directly or dynamically, using the {} notation
  3. Pass the required GlideRecord data as strings, using the GlideRecord getValue() or JS toString() function, inside the object defined in step 2
  4. Loop through the data array in the HTML template like here : ng-repeat="record in data.info"
  5. Use the required data in the HTML template using the {{record.fieldName}} notation


As for the :: notation, I found in the AngularJS doc that it is defined as:


One-time binding


An expression that starts with :: is considered a one-time expression


So what I understand is that by default, the expression is watched.   But with :: , it is not.



Let me know if you disagree with what I found.



Thanks.


Hi Yves,



You can refer few out of box widgets to build your functionality. Below is an example to retrieve approvals and push it to an array and in HTML, loop through the array.



find_real_file.png




You can also watch the below ask the expert episode, which has a good example.


Ask the Expert: Service Portal, TechNow 28



For the double colon, you are correct. It tells angular not to change it.



find_real_file.png



Please mark this response as correct or helpful if it assisted you with your question.