Access Error with custom form script

Comments

6 comments

  • Sree Vani Amara Principal Product Manager
    Engaged
    Answer Pro
    Celigo University Level 4: Legendary

    Hi Sukhbirsingh Khalsa

    Please refer to the document to use virtual export within a form.  

    Let us know if you have any further questions! 

    Thanks. 

    1
  • Sukhbirsingh Khalsa

    Hey Sree Vani Amara Thanks for your comment, I'm in in need to get more than 100 options in my exportSelect

    I referred this one doc, where Tyler Lamparter wrote if we want more than 100 we need to go with script path. but I get that access error as I have highlighted in my post.

    So, need help to get more than 100 options, if you can please help with access error.

    0
  • Tyler Lamparter Principal Product Manager
    Awesome Follow-up
    Engaged
    Top Contributor
    Answer Pro
    Celigo University Level 4: Legendary

    Sukhbirsingh Khalsa it's tough to say what you've got wrong here, but this is working for me.

    import {
        connections,
        integrations,
        exports,
        imports,
        flows,
        request
    } from 'integrator-api'

    class Form {
        // { fieldMap: {}, layout: { fields: [] } }
        constructor() {
            this.fieldMap = {};
            this.layout = {};
            this.layout.containers = [];
        }

        fields(...fields) {
            this.layout.fields = fields;
        }

        container(type, label, ...fields) {
            this.layout.containers.push({
                type: type,
                containers: [{
                    label: label,
                    fields: fields
                }]
            });
        }

        column(label, ...fields) {
            this.layout.type = 'column';
            this.layout.containers.push({
                label: label,
                fields: fields
            });
        }
    }
      
    class Field {
        constructor(id, name, label, type) {
            this.id = id;
            this.name = name;
            this.label = label;
            this.type = type;
        }

        isRequired() {
            this.required = true;
        }
        
        removeInvalidValues() {
            this.removeInvalidValues = true;
        }

        canBeDeleted() {
            this.showDelete = true;
        }

        isMultiline() {
            this.multiline = true;
        }

        description(description) {
            this.description = description;
        }

        help(helpText) {
            this.helpText = helpText;
        }

        typeOfInput(type) {
            this.inputType = type;
        }

        default(defaultValue) {
            this.defaultValue = defaultValue;
        }

        delimiter(delimiter) {
            this.delimiter = delimiter;
        }

        keyNamePlaceholder(keyName) {
            this.keyName = keyName;
        }

        valueNamePlaceholder(valueName) {
            this.valueName = valueName;
        }

        mode(mode) {
            this.mode = mode;
        }

        addOption(arg1, arg2) {
            if (!this.hasOwnProperty('options')) {
                this.options = [{
                    items: []
                }];
            }

            if (arg2) {
                this.options[0].items.push({
                    label: arg1,
                    value: arg2
                });
            } else {
                this.options[0].items.push(arg1);
            }
        }

        addStaticMapOptions(keyName, keyLabel, keyOptions, valueName, valueLabel, valueOptions) {
            this.keyName = keyName;
            this.keyLabel = keyLabel;
            this.keyOptions = keyOptions;
            this.valueName = valueName;
            this.valueLabel = valueLabel;
            this.valueOptions = valueOptions;
        }    
    }

    function formInit(options) {
        let form = new Form();
        // reference: https://docs.celigo.com/hc/en-us/articles/360059205112-Common-form-fields
        // deconstruct form to make access to fieldMap for prop assignment simpler
        let { fieldMap } = form;

        //create field for staticMap
        fieldMap.errorList = new Field('errorList','errorList','Errors(s)', 'multiselect');
        let ioConnectionId = "";
        for (let c of options.parentResource.aliases) {
          if (c.alias === "io") {
            ioConnectionId = c._connectionId;
          }
        }
        let selectOptions = getErrorList(ioConnectionId);
        for (let s of selectOptions) {
          fieldMap.errorList.addOption(s.label,s.value);
        }
        fieldMap.errorList.description('Select the errors you want to retry.');
        fieldMap.errorList.removeInvalidValues();

        //set the layout for the form
        form.fields(...['errorList']);

        // wrap up by assigning form to options.resource.settingsForm prop; return the form as well
        options.resource.settingsForm.form = form;
        return form;
    }

    function getErrorList(integrator_io_http) {
        return exports.runVirtual({
            "export": {
              "name": "Get errors",
              "_connectionId": integrator_io_http,
              "asynchronous": true,
              "oneToMany": false,
              "sandbox": false,
              "http": {
                  "relativeURI": "/v1/flows/6526bcdc901c6d2a153973d7/6526bccd901c6d2a153972f9/errors",
                  "method": "GET",
                  "formType": "http",
                  "paging": {
                      "method": "url",
                      "path": "nextPageURL"
                  },
                  "response": {
                      "resourcePath": "errors"
                  }
              },
              "transform": {
                  "type": "expression",
                  "expression": {
                      "rules": [
                          []
                      ],
                      "rulesTwoDotZero": {
                          "mappings": [
                              {
                                  "generate": "value",
                                  "dataType": "string",
                                  "extract": "$.errorId",
                                  "status": "Active",
                                  "sourceDataType": "string"
                              },
                              {
                                  "generate": "label",
                                  "dataType": "string",
                                  "extract": "$.code",
                                  "status": "Active",
                                  "sourceDataType": "string"
                              }
                          ],
                          "mode": "create"
                      },
                      "version": "2"
                  },
                  "rules": [
                      []
                  ],
                  "version": "2"
              },
              "adaptorType": "HTTPExport"
          }
        }).data;
    }
    1
  • Sukhbirsingh Khalsa

    Hey Sree Vani Amara and Tyler Lamparter, thanks a bunch for your quick input and solutions.

    I'm able to see the select dropdown now. The problem was when we click the flow builder button and write a script there it doesn't allowed me to execute it and throws that error and for some reason after saving too it was not displaying the results I'm getting now.

    You guys rock, cheers!

    0
  • Tyler Lamparter Principal Product Manager
    Awesome Follow-up
    Engaged
    Top Contributor
    Answer Pro
    Celigo University Level 4: Legendary

    Sukhbirsingh Khalsa yes you can't preview these scripts when using integrator api calls in them and you need to save it to check if it works. We'll take your feedback to enhance the preview functionality when using integrator apis in scripts. 

    1
  • Sukhbirsingh Khalsa

    Tyler Lamparter yes, that will be great if you write it somewhere those areas are restricted and you need to save the script to see the changes in form builder UI. or it can be small thread explaining how to go with forminit() script with video or screenshots.

    0

Please sign in to leave a comment.