VMware Aria

 View Only
  • 1.  Service broker: cannot parse MimeType in custom forms

    Posted Sep 27, 2024 08:28 AM

    Hello everyone,

    I need your help to solve a problem that is driving me crazy : I got an error from service broker, trying to parse a file passed as inputFile(Mime).

    I'll explain my usecase:

    • users upload a txt into Service broker with a list of vms (VMs List)
    • In VMs field I put an action that parse "VMs List" and check if the vm exists in our environment

    If I run the workflow in Orchestrator, everything runs fine :

    but if run from Service Broker, it fails with error :

    I'm running on 8.18 Automation and the code for checkVmsFromFile is here :

    //load file content split by lines
    var fileContent = inputfile.content.split(/\r\n|\n/)
    //System.log("fileContent > " + fileContent)
    vmWithError = new Array()
    
    
    for each (var vmName in fileContent) {
        //System.log("vmName > " + vmName)
        var found = Server.findAllForType("VC:VirtualMachine", "xpath:name='" + vmName + "'")
        //System.log(found.length)
        //check if the inserted vm exists or not    
        if ( found.length == 0) {
            System.log(vmName + " NOT FOUND")
            vmWithError.push(vmName + " NOT FOUND")
        }
    }
    
    
    if ( vmWithError.length == 0 ) {
        vmWithError.push("Check VMs SUCCESSFULLY Completed")
    }
    
    
    return vmWithError.sort()

    Can someone help me to solve this problem ?



  • 2.  RE: Service broker: cannot parse MimeType in custom forms

    Posted Sep 30, 2024 02:29 AM

    I had a similar issue where I was trying to use input validation for MimeAttachment inputs and got the same error. I opened and case and received the following repsonse: "Upon checking internally I confirmed that unfortunately using file uploads in service broker is not supported. You can use them only if you are running the workflow directly in vRO. "

    What is working in my case is simply use MimeAttachments as inputs but don't do the the input validation. Just pass is to the workflow. In the first step I validate the correct MimeType and fileextension. If that fails the workflow fails too.

    In your case another approach could be to use the TextArea input and let the user just paste the list of VMs as a string and than process this string by splitting it to allow multiple ways of input, like comma, semiclon, space or tab seperation. Something like the following and then go on from there.

    var array = input.replace(/["']/g, "").split(/[\s\n,;]/g);




  • 3.  RE: Service broker: cannot parse MimeType in custom forms

    Posted Sep 30, 2024 05:49 AM

    Hi Valentin ,

    thanks for your reply, I also opened a case that is still "Under Investigation" by Broadcom.

    I like your approach and will use it as a workaround and hope the problem will be solved.




  • 4.  RE: Service broker: cannot parse MimeType in custom forms

    Posted Oct 01, 2024 08:37 AM

    Back to you mate ... with a different error. As for mime, also this work-around runs smmotly in orchestrator and Service Broker fails :

    the code of the action is :

    var content = inputText.replace(/["']/g, "").split(/[,;\r\n|\n]/g);
    
    var vmWithError = new Array()
    for each (var vmName in content) {
        //System.log("vmName > " + vmName)
        var found = Server.findAllForType("VC:VirtualMachine", "xpath:name='" + vmName + "'")
        //System.log(found.length)
        //check if the inserted vm exists or not    
        if ( found.length == 0) {
            System.log(vmName + " NOT FOUND")
            vmWithError.push(vmName + " NOT FOUND")
        } else {
            //
        }
    }
    
    if ( vmWithError.length == 0 ) {
        vmWithError.push("Check VMs SUCCESSFULLY Completed")
    }
    
    return vmWithError.sort().toString()

    where inputText is the text area




  • 5.  RE: Service broker: cannot parse MimeType in custom forms

    Posted Oct 01, 2024 09:48 AM

    I tried recreating it and for me it works in service broker. I did it like this:

    Action Code:

    // Return empty array if input is not present
    if (!vms) {
        System.log("List is empty")
        return [];
    }
    
    // Split input to array
    var list = vms.replace(/["']/g, "").split(/[,;\r\n|\n]/g);
    
    // Cleanup
    var arr = list.filter(function(el) {
        return el != null && el !== '';
    });
    
    // Get all VMs
    var allVMs = VcPlugin.getAllVirtualMachines(["name"], null);
    System.log("Total VMs: " + allVMs.length);
    
    // Create empty array
    var vmsNotFound = [];
    
    // Interate over cleaned up list of VM names
    arr.forEach(function(vmName) {
        // Check if VM name exists
        var result = allVMs.filter(function(vm) {
            return vm.name.toLowerCase() === vmName.toLowerCase().trim();
        });
        // Push to list of not found VMs when above query does not return any results
        if (!result || result.length === 0) {
            vmsNotFound.push(vmName)
        }
    });
    
    // Return list of not found VM names
    return vmsNotFound;
    

    Workflow with two variables, one string, one array of string.

    Value options for "check" map to "vms".

    This works in service broker.

    "Check" contains the list of not found VM names.

    Workflow does run too and completes.




  • 6.  RE: Service broker: cannot parse MimeType in custom forms

    Posted Oct 02, 2024 06:48 AM

    thanks mate, it works!




  • 7.  RE: Service broker: cannot parse MimeType in custom forms

    Posted Mar 05, 2025 12:39 PM

    I was able to achieve this using the following approach:

    1. Use a data grid for file uploads – In the catalog item workflow, set the input type to Array/MimeAttachment to handle multiple file uploads.
    2. Configure the validation action – The input parameter that receives the file list in the validation action should be of type string.
    3. Bind the input in YAML – In the request form YAML configuration, add a binding to link the file upload field to the validation action input.

    Schema

    In the request form YAML, you need to define the binding correctly so that the file uploads are passed to the validation action.

    validation action inputs from yaml:

    Note: The field binding will appear empty in the validation action menu on the "Validations" tab, but the method still works as expected.

    the action which will validate has the input as shown:



    P.S. This method is specifically for validating a list of files. However, I've also successfully validated a single file upload using a similar approach.

    this is the field as shown on the request form itself





  • 8.  RE: Service broker: cannot parse MimeType in custom forms

    Posted Mar 09, 2025 01:23 PM
    Edited by xian Mar 09, 2025 01:23 PM

    That's an excellent idea, @Gai Hefetz

    Based on that I was able to compile what @SistDip wanted. Here is the combined code:

    if (!file) return [];
    var fileJson = JSON.parse(file);
    var fileName = fileJson.label;
    var fileValue = fileJson.value;
    var b64content = fileValue.substring(fileValue.lastIndexOf(',') + 1);
    var inputfile = new MimeAttachment();
    inputfile.buffer = new ByteBuffer(b64content);
    
    var fileContent = inputfile.content.split(/\r\n|\n/)
    vmWithError = new Array()
    
    
    for each (var vmName in fileContent) {
        //System.log("vmName > " + vmName)
        var found = Server.findAllForType("VC:VirtualMachine", "xpath:name='" + vmName + "'")
        //System.log(found.length)
        //check if the inserted vm exists or not    
        if ( found.length == 0) {
            System.log(vmName + " NOT FOUND")
            vmWithError.push(vmName + " NOT FOUND")
        }
    }
    
    if ( vmWithError.length == 0 ) {
        vmWithError.push("Check VMs SUCCESSFULLY Completed")
    }
    
    return vmWithError.sort()

    The input of this action is String, output is Array of String. I have added it to the custom form, but could bind it to the file input by manually adjusting the form yaml:

      file:
        label: file
        type:
          dataType: file
          isMultiple: false
      multiSelect_cb2a17e7:
        label: VMs
        type:
          dataType: string
          isMultiple: true
        valueList: []
        constraints: {}
        default:
          type: scriptAction
          id: com.test/checkVMsFromFile
          parameters:
            - file: file
              $type:
                dataType: string
                isMultiple: false

    Here is how it looks like once the file is uploaded:

    I found one drawback: even if a new file is uploaded, the Array below is not refreshed.