Why is my Ajax script and Client script not working. unable to call the records from Leave bucket

MG_Azam
Tera Contributor

Hi Community,

Need your help with the Ajax code (Script include) and client script.

This code is created to call the record from the leave bucket and populate the respective fields in the new leave request form. variables are correct, but some how the code is not working (unable to pull the record and populate)

 

Screenshot 2023-10-29 153923.pngScreenshot 2023-10-29 153946.png

1 ACCEPTED SOLUTION

@MG_Azam I asked you to make changes in the Client script only. Your script include script should remain same.

In a nutshell, your ImsAjax should look like the following 

Screenshot 2023-10-29 153946.png

 

And your Populate leave data should have the following code.

Screenshot 2023-10-29 234800.png

Hope this clears out all the confusion and resolves your issue.

View solution in original post

10 REPLIES 10

Since the script is running a GlideRecord on a custom table, you'll have to investigate to see why it's not finding the record.  It sounds like you have confirmed the Script Include is running, which is a good start.  You also need to confirm with info messages/logs the value passed in from the client for sysparm_user and sysparm_leavetype.  You can then use these values in a manual filtering of a list view on your custom table to confirm that the intended record is displayed for the employee and leave_type.  Your GlideRecord in your Script Include should retrieve the same record as the manual filtering of the list view, or else filter the list view to show the record you want, then change your GlideRecord to match.  Once you confirm you are inside the if(gr.next()){ then you can confirm that the values of accrued, balance, and taken are pushed to the object then returned to the client.  If you're still stuck, post the most recent version of your scripts, and a list view of the custom table filtered to the intended record, also copying the query from the last breadcrumb. 

Sandeep Rajput
Tera Patron
Tera Patron

@MG_Azam Found a couple of issues in your client script.

Here is the summary.

Screenshot 2023-10-29 153923.png

Replace line number 17,18 and 19 with the following lines and your client script will work.

 

 

g_form.setValue('accrued',result.accrued);
g_form.setValue('balance',result.balance);
g_form.setValue('taken',result.taken);

 

Please mark the answer correct and helpful if it manages to solve your issue.

Hi @Sandeep Rajput ,

Thanks for helping it is not working  still this is how the scripts are looking currently.

1st. Ajax.  2nd. Client Script

 

 

Screenshot 2023-10-29 234736.pngScreenshot 2023-10-29 234800.png

 

@MG_Azam I asked you to make changes in the Client script only. Your script include script should remain same.

In a nutshell, your ImsAjax should look like the following 

Screenshot 2023-10-29 153946.png

 

And your Populate leave data should have the following code.

Screenshot 2023-10-29 234800.png

Hope this clears out all the confusion and resolves your issue.

Hi @Sandeep Rajput  ,

this is how the script is looking currently, and still not working 😩

 

Screenshot 2023-10-30 150958.pngScreenshot 2023-10-30 151019.png