Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8818139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:01:38+00:00 2026-06-14T05:01:38+00:00

I have a webscript set up on the repo-side in Alfresco. The webscript uses

  • 0

I have a webscript set up on the repo-side in Alfresco. The webscript uses the POST method, accepts and returns json and is simply designed to set some properties to support a client-side ajax app.
The controller code for the script is as follows:

/**
 * Document Bundle Management Property setter method
 *
 * @method POST
 */

function main() {
        var nodeRef=args.doc,
            salesOrderNumber=json.get("salesOrderNumber"),
            stockCode=json.get("stockCode"),
            VIN=json.get("VIN"),
            customerCode=json.get("customerCode"),
            resultObj={result:"failure",problems:[],debug:[]};
        resultObj.debug.push("Webscript begins. Variables:");
        resultObj.debug.push("\tsalesOrderNumber: " + salesOrderNumber);
        resultObj.debug.push("\tstockCode: " + stockCode);
        resultObj.debug.push("\tVIN: " + VIN);
        resultObj.debug.push("\tcustomerCode:" + customerCode);
        if (nodeRef) {
                resultObj.debug.push("Received nodeRef variable. Checking validity");
                doc=utils.getNodeFromString(nodeRef);
                if (doc && doc.isDocument) {
                        resultObj.result="success";
                        resultObj.debug.push("nodeRef valid, checking document type");
                        if (doc.isSubType("my:documentBundle")) {
                                resultObj.debug.push("Document is already of type my:documentBundle. Not specializing");
                        } else {
                                resultObj.debug.push("Document is not of type my:documentBundle. Specializing");
                                doc.specializeType("my:documentBundle");
                        }
                        if (salesOrderNumber && salesOrderNumber.length && salesOrderNumber.length>0) {
                                doc.properties["salesOrderNumber"]=salesOrderNumber;
                                resultObj.debug.push("Set document salesOrderNumber to " + salesOrderNumber);
                        } else {
                                resultObj.debug.push("salesOrderNumber was not received, was blank or of zero length. ignoring");
                        }
                        if (stockCode && stockCode.length && stockCode.length>0) {
                                doc.properties["stockCode"]=stockCode;
                                resultObj.debug.push("Set document stockCode to " + stockCode);
                        } else {
                                resultObj.debug.push("stockCode was not received, was blank or of zero length. ignoring");
                        }
                        if (VIN && VIN.length && VIN.length>0) {
                                doc.properties["VIN"]=VIN;
                                resultObj.debug.push("Set document VIN to " + VIN);
                        } else {
                                resultObj.debug.push("VIN was not received, was blank or of zero length. ignoring");
                        }
                        if (customerCode && customerCode.length && customerCode.length>0) {
                                doc.properties["customerCode"]=customerCode;
                                resultObj.debug.push("Set document customerCode to " + customerCode);
                        } else {
                                resultObj.debug.push("customerCode was not received, was blank or of zero length. ignoring");
                        }
                        doc.save();
                        resultObj.debug.push("document saved");
                } else {
                        resultObj.problems.push("Invalid nodeRef supplied!");
                }
        } else {
                resultObj.problems.push("No nodeRef supplied!");
        }
        model.obj=resultObj;
}

main();

My problem occurs in the 4 lines like: if (salesOrderNumber && salesOrderNumber.length && salesOrderNumber.length>0) {, which always seem to evaluate false even when I am sure the variable contains a string that is not zero length. If I look at the debug property returned I see the following:

0: "Webscript begins. Variables:"
1: "    salesOrderNumber: test"
2: "    stockCode: test"
3: "    VIN: test"
4: "    customerCode:test"
5: "Received nodeRef variable. Checking validity"
6: "nodeRef valid, checking document type"
7: "Document is already of type my:documentBundle. Not specializing"
8: "salesOrderNumber was not received, was blank or of zero length. ignoring"
9: "stockCode was not received, was blank or of zero length. ignoring"
10: "VIN was not received, was blank or of zero length. ignoring"
11: "customerCode was not received, was blank or of zero length. ignoring"  
12: "document saved"

So, I can see that all four variables have the value “test”. If in firebug or the js console I enter

a="test";
if (a && a.length && a.length>0) then console.log("true") else console.log("false")

I get true output, as expected.
I don’t see what could be affecting this – I use this incredibly basic condition almost daily to test strings before I use them but I am obviously missing something this time. help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:01:40+00:00Added an answer on June 14, 2026 at 5:01 am

    Edit: Based on your comment below, I have a new theory. Since these appear to be some sort of objects and not primitive strings, the length method is what’s causing the trouble:

    This simple test behaves exactly the same way as your problem:

    var x = {
        toString: function() { return 'test'; },
        length: function() { return 'something'; }
    };
    
    console.log('x is: ' + x);
    if (x && x.length && x.length > 0)
        console.log('passed');
    else
        console.log('failed');
    

    It reports to be “test” when you concatenate it to a string, but it fails the test because length > 0 is false because length is a function. I would recommend converting it to a string.


    Also, I would point out that some of your tests are unnecessary. salesOrderNumber.length > 0 will be false if and only if salesOrderNumber.length is falsey. Likewise, salesOrderNumber.length will only be falsey if and only if salesOrderNumber is the empty string (for a string), so you can simply:

    salesOrderNumber = String(salesOrderNumber);
    if (salesOrderNumber)
        console.log('ok');
    else
        console.log('oops');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some simple .NET objects I'd like to serialize to JSON and back
I have a simple object that is deserialized from JSON into a server-side object.
I have a REST-service that returns JSON. But the JSON response returned with \
Have a painfully simple blog Post creator, and I'm trying to check if the
have 2 questions : A computer with 32-bit address uses 2-level page table (9
I have a problem with AllDay events, in a fullcalendar, if i set allday
I have been working on a JQuery script that posts JSON to my asp.net
I have a JSON object that I need to pass from the server to
I have a VBScript app which create Symbolic Links. Set wshell = CreateObject(WScript.Shell) .....
I have the following .VBS script, which works, but it only returns the top

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.