- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
The h.e.l.p. Blog 5/11/11
This week, Joe and I were assigned a new project! Our tasks included things like form changes, creating list views, gauges, record producers, and custom widgets. This was all very exciting until I came across a small problem, GlideAjax.
One of our tasks was to make a field yellow when the additional comments was updated by an ITIL user and no color once the end user viewed the ticket. So I started out by adding a true/false field to my form to act as a flag. Next, I created a business rule to set the flag to true if an ITIL user updated the additional comments. I then proceeded to make an onLoad client script which would check the value of the flag and set it to false if the end user who created the ticket was viewing it. After minutes of testing this out, I found that the flag's value was not being updated on the server. After speaking with my team lead, I was informed that I would have to make a call to the server in order to update the flag. Right away, I went to the Wiki (http://wiki.service-now.com/index.php?title=GlideAjax) and started diving in. Two and a half hours later, I had a working server call and was able to solve my problem.
During that time period, I spent most of my time trying to understand how server calls work, what things I needed to pass to the server, and how callback functions work. I had to re-read the wiki article multiple times because I kept overlooking important details. So for those who have not worked with GlideAjax, here are some good tips.
1.Read the wiki article carefully.
2.If you are making a server call from a client script, the script include (server side) must be client callable. The wiki article has a great example, which you can modify so that you do not have to start from scratch.
3.Decide which things you need to pass to the server in order for the server to process your request. For example, does the server need to know the sys_id of the record that you are on? (See this wiki article on getting the sys_id via client script: http://wiki.service-now.com/index.php?title=Unique_Record_Identifier).
4.variable.addParam("sysparm_name", function_name) will call the function in the script include. This is the first line after declaring your GlideAjax variable.
5.When sending things to the server, you must use the addParam() function. The function has two parameters, the parameter name and the value. The parameter name must always being with "sysparm_". What ever comes after the underscore is up to you. My convention was to use the name of my fields. (Note that there are predefined parameters as stated in the wiki article that you should avoid using).
6.It is recommended that you use a callback function. This is optional, but if not used, the browser could be blocked waiting for the response from the server. (This is explained in the wiki article. In my code, I just renamed the callback function used in the example).
7.To test your client script and server include, put in some trace statements. You can put in alerts for the client scripts and "gs.log" for the script include. This will help determine what is happening both on the client and server side.
Just remember, learning this for the first time is the hardest. Through lots of trial and error, you will start to see things how things work and what you left out (parameters). If you have any questions or examples of how you use GlideAjax, please post it here.
Thanks,
davida.hughes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.