- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 09:17 AM
Hello! I have a requirement where I have to autopopulate a field in the form only when it is submitted . How to write a client script for this? Are there any other ways to implement it?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 11:01 AM - edited 08-18-2023 11:03 AM
Hi @Aditya Sinha,
To auto-populate logged in user in field. I mean, in reference field you can set default value as
javascript:gs.getUserID();
For String field, use default value as:
javascript:gs.getUserDisplayName();
Refer attached text file.
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 09:24 AM
Hi @Aditya Sinha,
You can try it by two ways.
On Submit Client scripts:
unction onSubmit() {
g_form.setValue("field_name", new Date());
}
Before Insert/update Business rule:
current.setValue("field_name", new GlideDate());
or
current.setValue("field_name", new GlideDateTime());
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 04:48 AM
Hi Sagar.
I have a variant of this requirement where I have to populate the current logged in user in a filed of the form. Can you help with the code of this?
Your answer above was very helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 06:23 AM
Hello @Aditya Sinha ,
Just a small twig to the code suggested by @Sagar Pagar
var currentUser = gs.getUser();
var record = new GlideRecord('table_name');
record.initialize();
record.setValue('field_name', currentUser.getID());
record.insert();
Try this
Thanks,
Amarjeet Pal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 11:01 AM - edited 08-18-2023 11:03 AM
Hi @Aditya Sinha,
To auto-populate logged in user in field. I mean, in reference field you can set default value as
javascript:gs.getUserID();
For String field, use default value as:
javascript:gs.getUserDisplayName();
Refer attached text file.
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar