Home

Results 1 to 2 of 2

Thread: ScriptVault.JSON

Threaded View

  1. #1
    Join Date
    Dec 2007
    Location
    Melbourne, Victoria, Australia
    Posts
    913

    ScriptVault.JSON

    Is it just me, or do the ScriptVault.JSON functions appear to be flimsy at the best of times?

    We have an attribute that is a JSON string. The workflow activity is set to update this by converting the string to an object, updating the object value, then returning the object back to a string and writing it back to the directory. However, every time it now outputs:

    Code:
    TypeError: Cannot read property "apply" from undefined
    I can only assume the ScriptVault.JSON is sourced from /IDMProv/com.novell.srvprv.impl.gwt.gwtControls/js/lib/json2.js and the offending line appears to be:

    Code:
    if (Object.prototype.toString.apply(value) === '[object Array]') {
    The code is:

    Code:
    var taskDetails = IDVault.get(flowdata.get('Request/display/actionObject'), 'objectKey', 'attrKey');
    trace("UpdateAction: taskDetails " + taskDetails.toString(), 3);
    try
    { 
        var taskJSON = ScriptVault.JSON.parse(taskDetails.toString());
        var incident = flowdata.get('Request/approval/incident/result');
        trace("UpdateAction: incident " + incident.toString(), 3);
        var business = flowdata.get('Request/approval/business/result'); 
        trace("UpdateAction: business " + business.toString(), 3);
        if (taskJSON.IncidentControlCentre == "true")
        {
            taskJSON.IncidentControlCentre = incident.toString();
        }
        if (taskJSON.CarPark == "true")
        {
            taskJSON.CarPark = business.toString();
        }
        if (taskJSON.CommsRoom == "true")
        {
            taskJSON.CommsRoom = business.toString();
        }
        taskDetails = ScriptVault.JSON.stringify(taskJSON);
        taskDetails = "{\"data\":" + taskDetails.toString() + "}";
    }
    catch(e)
    {
        trace("UpdateAction: Error " + e, 1);
    }
    trace("UpdateAction: taskDetails " + taskDetails.toString(), 3);
    taskDetails.toString();
    The output is this:

    Code:
    UpdateAction: taskDetails {"IncidentControlCentre":"true","serviceComments":"","CarPark":"true","currentInternalEmail":"","Instructions100_1":"{p}{b style='color: red;'}Notes:{\/b}{br\/}{b}^{\/b} Access must be endorsed by Business Services.{br\/}{b}^^{\/b} Access must be endorsed by Incident Response.{br\/}{b}^^^{\/b} Please provide details in Comments section.{\/p}","action":"Add","BikeCage":"true","Level3":"true","CommsRoom":"true","Level8":"true","Level9":"true","serviceName":"Building Security","AccessLevel":"General (7am to 7pm 5 days)","currentEmail":"","param1":"0400000000","undefined":"undefined","GoodsLift":"true","Level10":"true","SecureRooms":"false","AccessType":"Short Term Contractor\/Consultant","requestType":"Add Person (Line Manager Approval)","subRequestType":"Add Person (Line Manager Approval)"}
    UpdateAction: incident true
    UpdateAction: business true
    UpdateAction: Error TypeError: Cannot read property "apply" from undefined
    UpdateAction: taskDetails {"IncidentControlCentre":"true","serviceComments":"","CarPark":"true","currentInternalEmail":"","Instructions100_1":"{p}{b style='color: red;'}Notes:{\/b}{br\/}{b}^{\/b} Access must be endorsed by Business Services.{br\/}{b}^^{\/b} Access must be endorsed by Incident Response.{br\/}{b}^^^{\/b} Please provide details in Comments section.{\/p}","action":"Add","BikeCage":"true","Level3":"true","CommsRoom":"true","Level8":"true","Level9":"true","serviceName":"Building Security","AccessLevel":"General (7am to 7pm 5 days)","currentEmail":"","param1":"0400000000","undefined":"undefined","GoodsLift":"true","Level10":"true","SecureRooms":"false","AccessType":"Short Term Contractor\/Consultant","requestType":"Add Person (Line Manager Approval)","subRequestType":"Add Person (Line Manager Approval)"}
    When I repeat the code in a simple HTML document:

    Code:
        var taskDetails = '{"IncidentControlCentre":"true","serviceComments":"","CarPark":"true","currentInternalEmail":"","Instructions100_1":"{p}{b style=\'color: red;\'}Notes:{\/b}{br\/}{b}^{\/b} Access must be endorsed by Business Services.{br\/}{b}^^{\/b} Access must be endorsed by Incident Response.{br\/}{b}^^^{\/b} Please provide details in Comments section.{\/p}","action":"Add","BikeCage":"true","Level3":"true","CommsRoom":"true","Level8":"true","Level9":"true","serviceName":"Building Security","AccessLevel":"General (7am to 7pm 5 days)","currentEmail":"","param1":"0400000000","undefined":"undefined","GoodsLift":"true","Level10":"true","SecureRooms":"false","AccessType":"Short Term Contractor\/Consultant","requestType":"Add Person (Line Manager Approval)","subRequestType":"Add Person (Line Manager Approval)"}';
        document.write("<p><pre>" + taskDetails + "</pre></p>");
        try
        {
            var taskJSON = JSON.parse(taskDetails);
            var incident = true;
            document.write("<p><pre>incident " + incident.toString() + "</pre></p>");
            var business = true; 
            document.write("<p><pre>business " + business.toString() + "</pre></p>");
            if (taskJSON.IncidentControlCentre == "true")
            {
                taskJSON.IncidentControlCentre = incident.toString();
            }
            if (taskJSON.CarPark == "true")
            {
                taskJSON.CarPark = business.toString();
            }
            if (taskJSON.CommsRoom == "true")
            {
                taskJSON.CommsRoom = business.toString();
            }
            taskDetails = JSON.stringify(taskJSON);
            taskDetails = "{\"data\":" + taskDetails.toString() + "}";
        }
        catch (e)
        {
            document.write("<p><pre>Error: " + e + "</pre></p>");
        }
        document.write("<p><pre>" + taskDetails + "</pre></p>");
    It works like a charm:

    Code:
    {"IncidentControlCentre":"true","serviceComments":"","CarPark":"true","currentInternalEmail":"","Instructions100_1":"{p}{b style='color: red;'}Notes:{/b}{br/}{b}^{/b} Access must be endorsed by Business Services.{br/}{b}^^{/b} Access must be endorsed by Incident Response.{br/}{b}^^^{/b} Please provide details in Comments section.{/p}","action":"Add","BikeCage":"true","Level3":"true","CommsRoom":"true","Level8":"true","Level9":"true","serviceName":"Building Security","AccessLevel":"General (7am to 7pm 5 days)","currentEmail":"","param1":"0400000000","undefined":"undefined","GoodsLift":"true","Level10":"true","SecureRooms":"false","AccessType":"Short Term Contractor/Consultant","requestType":"Add Person (Line Manager Approval)","subRequestType":"Add Person (Line Manager Approval)"}
    incident true
    business true
    {"data":{"IncidentControlCentre":"true","serviceComments":"","CarPark":"true","currentInternalEmail":"","Instructions100_1":"{p}{b style='color: red;'}Notes:{/b}{br/}{b}^{/b} Access must be endorsed by Business Services.{br/}{b}^^{/b} Access must be endorsed by Incident Response.{br/}{b}^^^{/b} Please provide details in Comments section.{/p}","action":"Add","BikeCage":"true","Level3":"true","CommsRoom":"true","Level8":"true","Level9":"true","serviceName":"Building Security","AccessLevel":"General (7am to 7pm 5 days)","currentEmail":"","param1":"0400000000","undefined":"undefined","GoodsLift":"true","Level10":"true","SecureRooms":"false","AccessType":"Short Term Contractor/Consultant","requestType":"Add Person (Line Manager Approval)","subRequestType":"Add Person (Line Manager Approval)"}}
    Last edited by ScorpionSting; 18-May-2016 at 01:24 AM.
    Visit my Website for links to Cool Solution articles.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •