Mutate Transform Data Ressource

Eric54
Tera Expert

In UI builder I've created a new mutate transform data source.   It contains four properties.  But when I execute the instance of my data source the input is always an empty object {}.  I added the first line to help me debug and I can see the application log that input is an empty {}. Anyone have any ideas?

 
Here are my properties:

 

[
  {
    "name": "visitTitle",
    "label": "Visit Title",
    "readOnly": false,
    "fieldType": "string",
    "mandatory": true,
    "defaultValue": ""
  },
  {
    "defaultValue": "{\"id\":\"1b90eb8e1b5afc1078230d47dc4bcbc3\",\"label\":\"Smith, John\"}",
    "description": "A sponsor item",
    "fieldType": "json",
    "label": "Visit Sponsor",
    "name": "visitSponsor",
    "readOnly": false,
    "required": true,
    "typeMetadata": {
      "schema": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "label": {
            "type": "string"
          }
        },
        "required": ["id", "label"]
      }
    }
  },
  {
    "defaultValue": "[{\"id\":\"1b90eb8e1b5afc1078230d47dc4bcbc3\",\"label\":\"0109\"}]",
    "description": "An array of Rooms",
    "fieldType": "json",
    "label": "Visit Rooms",
    "name": "visitRooms",
    "readOnly": false,
    "required": true,
    "typeMetadata": {
      "schema": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "label": {
              "type": "string"
            }
          },
          "required": ["id", "label"]
        }
      }
    }
  },
  {
    "description": "The visit type stored in the visit record.",
    "fieldType": "choice",
    "label": "Visit Type",
    "name": "visitType",
    "readOnly": false,
    "required": true,
    "typeMetadata": {
      "choices": [
        {
          "label": "Visitor",
          "value": "v"
        },
        {
          "label": "Gallery",
          "value": "g"
        },
        {
          "label": "Tour",
          "value": "t"
        }
      ],
      "schema": {
        "type": "string",
        "enum": ["v", "g", "t"]
      }
    }
  }
]
​

 

This is some simplified code from the data resource:

 

function transform(input) {
    gs.info(JSON.stringify(input, null, 3));
    var output = {
        isSuccess: false
    };

    try {
        var visit_title = input.visitTitle;
        var visit_sponsor = input.visitSponsor;
        var visit_rooms = input.visitRooms;
        var visit_type = input.visitType;

        var first_location = "";
        var buildingId = "";
        var locations = [];

        for (var i = 0; i < visit_rooms.length; i++) {
            var room = visit_rooms[i];
            if (i === 0) {
                first_location = room.id;
            }
            locations.push(room.id);
        }

        // Get first room
        var fr = new GlideRecord('sn_wsd_core_room');
        if (fr.get(first_location)) {
            buildingId = fr.getValue("building");
        } else {
            throw new Error("Could not load the selected room.");
        }

        // Create Event sn_wsd_case_workplace_case
        var c = new GlideRecord('sn_wsd_case_workplace_case');
        c.initialize();
        ... <Setting my case properties> ...

        var caseId = c.insert();

        // Create Visit sn_wsd_visitor_visit
        var v = new GlideRecord('sn_wsd_visitor_visit');
        v.initialize();
        ... <Setting my visit properties> ...

        // Set output
        output.isSuccess = true;
        output.caseId = caseId;
        output.visitId = visitId;
    } catch (ex) {
        output.message = ex.message;
    }
    return output;
}

 

This is how I execute my DR:

 

    api.data.vms_create_event.execute({
        visitTitle: api.state.visit_title,
        visitSponsor: api.state.visit_sponsor,
        visitRooms: api.state.visit_rooms,
        visitType: api.state.visit_type
    });

 

 
I did verify my state is variables and they are OK.
1 ACCEPTED SOLUTION

Dibyaratnam
Tera Sage

Simplify the properties and to debug the input value, reduce the fields in the properties and keep debugging until you find the particular property causing the issue.

View solution in original post

3 REPLIES 3

Dibyaratnam
Tera Sage

Simplify the properties and to debug the input value, reduce the fields in the properties and keep debugging until you find the particular property causing the issue.

Eric54
Tera Expert

Looks like the properties were the culprit.   It did not like 

"required": true,

Eric54
Tera Expert

Looks like the problem was in my json properties.  I needed to add "valueType": "object" and

I also removed "required": true.