Number and Date Formatting not working when using "NSQuoteAgent.GetOrderConfirmation"

lock
push_pin
done
Besvarat
7

Hi,

You may have seen from a previous post (where I raised a question on document filename formats), that I have written a script that uses the "NSQuoteAgent.GetOrderConfirmation" function, to allow one of our customers to produce multple order documents against the same quote, but using different document templates for each document.

Our customer needs multiple templates against the quote, for things such as Works Order Sheet, Picking Form etc., and the "GetOrderConfirmation" function works really well, as it allows you to save in SuperOffice multiple "Order Confirmation" documents, using different "Order Confirmation" templates against the same quote.  Below is a screenshot of the script, that runs from the Sale Task menu.

The trouble is, that it does not seem to respect the user's Number and Date format when producing the document.

Below is a screenshot of part of an order confirmation document produced when raising the document in the normal manner (at the point of placing the order, which can only be done against one of the document templates for any given quote).  The date correctly shows in the UK date format, as per the customer's number and date format.

When I produce the same document via a CRM Script, using the following code.

    NSQuoteAgent quoteAgent;
    String quoteDoc = quoteAgent.GetOrderConfirmation(quoteVersionId, confirmationTemplateId);

This is the document it produces, with the user's number and date format being ignored.

As the script runs from the Sale Task menu, I expected the script to run in the context of the user, and therefore use the user's number and date format settings, but this seems not to be the case.

Am I missing something in my code, or is this a bug with the function in SuperOffice?

Many thanks,

Trevor

14. juli 2026 | 08:54 fm

Allt Svar (7)

Hi,


See this thread: https://community.superoffice.com/en/forums/user-forums/general-crm/crmscript.-dates-in-quote-documents-does-not-format-correctly

 

14. juli 2026 | 09:01 fm
Thanks David,

This does look a bit complicated, is there any further documentation on manually calling the API using the HTTP class via a CRM Script?

Also do you know if there is a wish logged to be able set the culture directly via a CRM Script, so that this is not needed?

Many thanks,

Trevor
14. juli 2026 | 09:10 fm

Hi,

There is this bug registered;

https://community.superoffice.com/en/product-releases/bugs-wishes/product-issue/?bid=37238&azure=1

This does look a bit complicated, is there any further documentation on manually calling the API using the HTTP class via a CRM Script?

You can call the the API like this, but do note you need an application token/client secret of a app authorized on the specific tenant to generate a valid access token;

#setLanguageLevel 4;

NSUserAgent userAgent;

Struct GetOrderConfirmationArgs
{
    Integer QuoteVersionId;
    Integer ConfirmationTemplateId;
};

GetOrderConfirmationArgs args;
args.QuoteVersionId = 1;
args.ConfirmationTemplateId = 2;

// app token is required otherwise we can't call the Web API
String appToken = "";

String url = getProgramBlogic().until("CS/") + "api/v1/Agents/Quote/GetOrderConfirmation";

HTTP httpClass;
  
httpClass.addHeader("Accept", "application/json");
httpClass.addHeader("Content-Type", "application/json");

httpClass.addHeader("Authorization", "Bearer " + userAgent.GetAccessToken(appToken, true));

httpClass.setOption("parameters", "? " + args.toJsonString());  

// enable utf8 so that characters are send correctly
httpClass.setOption("parametersUTF8", "true");

NSStream responseAsStream = httpClass.postAsStream(url);
  
if (httpClass.hasError() == true || httpClass.getValue("statusCode").toInteger() != 200)
{
    String errorMessage = "HTTP class returned error: " + httpClass.getErrorMessage();
    errorMessage += "\r\nStatus code returned: " + httpClass.getValue("statusCode");
    errorMessage += "\r\nResponse: \r\n " + String(responseAsStream.GetStream());

    throw errorMessage;
}

String quoteDocumentContent = String(responseAsStream);
14. juli 2026 | 09:30 fm
Hi David,

Thank you for this, this is really helpful. I will give this a go tomorrow.

Thanks again for your help, really appreciated.

Trevor
14. juli 2026 | 10:14 fm

Hi David,

So I have managed to change the code, so that it now creates the document using the HTTP Class, but the one problem is, is that it still seems to be ignoring the culture, despite me setting it in the headers.  See code below.

  HTTP httpClass;
    
  httpClass.addHeader("Accept", "application/json");
  httpClass.addHeader("Content-Type", "application/json");
  httpClass.addHeader("Authorization", "Bearer " + userAgent.GetAccessToken(appToken, true));
  httpClass.addHeader("SO-Culture", "en-GB");

  httpClass.setOption("parameters", "? " + args.toJsonString());

I am assuming I have done this correctly, and that the culture for the UK date format is "en-GB", but the Base64 string returned by the GetOrderConfirmation function is still displaying the dates in the incorrect format.

Do you have any ideas on what I am missing to get the date to display in the required format?

Many thanks,

Trevor

15. juli 2026 | 02:32 em

Hi,

Try setting SO-Language as well

httpClass.addHeader("SO-Language", "en-GB");
15. juli 2026 | 02:43 em

Thanks David, I will test this as soon as I can, it looks like SuperOffice SOD has just gone down (or at least ours has anyway).

 

15. juli 2026 | 02:50 em

Hi David,

Great news, adding the "SO-Language" header has fixed the issue.  Thank you for all of your help on this, I really do appreciate it.

On a bit of a side note (in case your interested), the line of code below doesn't work, when the CRM Script is run from a Task Menu in SuperOffice.

String url = getProgramBlogic().until("CS/") + "api/v1/Agents/Quote/GetOrderConfirmation";
 
The reason for this, is that when the "getProgramBlogic" command is run from the task menu, it returns an empty string.
 
I normally use the code below to get the base url.
 
Parser p;

String baseURL = p.parseString("[[config.cgiUrl]]").stripLeadingAndTrailing(" ");
baseURL = baseURL + p.parseString("[[config.wwwPath]]").stripLeadingAndTrailing(" ").before("CS/");

As of yet, I have not found anywhere in SuperOffice where this does not work.  I just thought you may be interested in knowing the getProgramBlogic does not work from the Task Menu, in case anyone else has an issue with it, and this isn't a bad workaround.

But once again, thanks for all your help on this.

Trevor

15. juli 2026 | 03:21 em

Hi,

Below should work for getting the API base url in all scenarios without having to use the parser class;

String getTenantApiBaseUrl()
{
    String blogicUrl = getProgramBlogic();

    // full url returned, so
    // https://app.superoffice.com/CustXXXX/CS/scripts/blogic.fcgi
    if (blogicUrl.caseBeginsWith("https://") == true)
    {
        return blogicUrl.until("CS/") + "api/v1/";
    }

    // only relative path returned, so:
    // /CustXXXX/CS/scripts/blogic.fcgi
    if (blogicUrl.caseBeginsWith("/") == true)
    {
        return getCgiUrl() + blogicUrl.until("CS/") + "api/v1/";
    } 

    throw "Unable to generate tenant API base url from blogic url '" + blogicUrl + "'";
}
15. juli 2026 | 03:52 em
Great, thanks David, that's really good to know.
15. juli 2026 | 04:50 em

Lägg till svar