Generic Field Update Script

Generic Field Update Script

Requirement:

Currently, every time one has to update a field with values, they need to adhere to a specific format, which can be challenging as not everyone is familiar with it. To simplify this process, we propose a generic function that can handle the formatting automatically.

Instead of remembering complex formats, users can simply provide values in a straightforward structure like this:

{
"category": "Hardware", "udf_sline_301": "Shawn Adams", "priority": "High", "scheduled_start_time": "1734500415037", "resolution": "Sample resolution" }

This input will be parsed and converted into the required format:

{
"request": { "udf_fields": { "udf_sline_301": "Shawn Adams" }, "category": { "name": "Hardware" }, "priority": { "name": "High" }, "scheduled_start_time": { "value": "1734500415037" } "resolution": { "content": "Sample resolution" } } }

By using this function, the need to remember or manually structure the field formats is eliminated, making the process faster and more user-friendly.

This function will work only if the provided keys adhere to the allowed format.  Refer to the documentation for the correct attribute names: ManageEngine API Documentation.

Example:
  1. The date and time field will only update if the value is provided as a Unix timestamp in milliseconds; otherwise, the update will not proceed.
  2. For picklist fields, the value used for the update must match the exact value in the picklist dropdown. Even minor discrepancies, such as an extra space, can prevent the update from occurring.
  3. If you are using this generic script for the Request module and need the request attributes, they can be found here: Request API Attributes.
For user-defined fields, refer to Admin > Additional Fields. Based on the module, the list of fields will be available. For Change module, you will need to use the response JSON output of a change to retrieve the API Field Name.



Steps to configure:
  1. Download the attached scripts.  
  2. Goto Admin > Developer Space > Global Function > Copy & Paste the attached GF_4 - Configuration.txt and save it with a name.
  3. Goto Admin > Developer Space > Global Custom Function > Copy & paste GF_genericFieldUpdate.txt and save it with a name.
    • The global function will accept a simplified input structure provided by the user, and the name of the module.
  4. We need to configure a module-level custom function to update the entity by calling the global function to automatically format the user-provided input and use the formatted data for the update.

  5. The custom functions for the Change module and Request module are attached as samples. Configure these functions in custom triggers, and set the invoking conditions based on your requirements.

  6. Request Module Configuration for reference

    1. Request Custom Function:


    2. Request Custom Trigger:


  7. Request Module Configuration for reference

    1. Change Custom Function:


    2. Change Custom Trigger:



Note: Updating UDF picklist fields in the Request module is supported only from builds above 14900.



                  New to ADSelfService Plus?