Methods
-
staticdocuments.sdk.utils.formatDate(date, options){String}
-
Formats an ECMAScript Date or a Moment.js Date object and returns it as a string using the date format for the current user. This string is accepted by date fields.
Name Type Description date
Date | Moment the date value to be formatted
options
Object optional Name Type Description fieldType
String optional The type the Date object should be formatted to. Either "date" or "timestamp"
dateType
String optional The input type of the Date. Either "ecma" (default) or "moment"
Returns:
Type Description String the formatted string value Examples
var fileContext = documentsContext.getFileContext(); //set the current date fileContext.setFileFieldValue("date", documents.sdk.utils.formatDate(new Date(), {fieldType: "date", dateType: "ecma"}));
var fileContext = documentsContext.getFileContext(); //set the current date fileContext.setFileFieldValue("date", documents.sdk.utils.formatDate(moment(), {fieldType: "date", dateType: "moment"}));
var fileContext = documentsContext.getFileContext(); //set the current date and time fileContext.setFileFieldValue("timestamp", documents.sdk.utils.formatDate(new Date(), {fieldType: "timestamp", dateType: "ecma"}));
var fileContext = documentsContext.getFileContext(); //set the current date and time fileContext.setFileFieldValue("timestamp", documents.sdk.utils.formatDate(moment(), {fieldType: "timestamp", dateType: "moment"}));
-
staticdocuments.sdk.utils.formatNumber(value, decimalSeparator_or_options, groupingSeparator, decimalPrecision){String}
-
Formats a number and returns it as string.
If any of the optionaldecimalSeparator
,groupingSeparator
ordecimalPrecision
parameters is not set, this function will use the default value of the current user locale configured in the Documents Manager.Name Type Description value
Number the number value to be formatted
decimalSeparator_or_options
String | Object optional the decimal separator character that should be used or an object that contains any of the
decimalSeparator
,groupingSeparator
ordecimalPrecision
optionsgroupingSeparator
String optional the grouping separator character
decimalPrecision
Number optional the decimal precision, if set to -1, it is left untouched
Returns:
Type Description String the formatted string value Examples
documents.sdk.utils.formatNumber(1910.96, ",", ".", -1); // "1.910,96"
documents.sdk.utils.formatNumber(1910.96, ",", ".", 0); // "1.911"
documents.sdk.utils.formatNumber(1910.96, ",", ".", 1); // "1.911,0"
documents.sdk.utils.formatNumber(1910.96, ",", ".", 2); // "1.910,96"
documents.sdk.utils.formatNumber(1910.96, ",", ".", 3); // "1.910,960"
documents.sdk.utils.formatNumber(1910.96, { decimalSeparator : ",", groupingSeparator : ".", decimalPrecision : 2 } // "1.910,96"
-
staticdocuments.sdk.utils.parseDate(date, options){Date|Moment}
-
Parses a date string and returns either a ECMAScript or a Moment.js Date object.
This method expects a string with the date format of the current user, for example by using FileContext#getFileFieldValue on a Date or Timestamp field.Name Type Description date
String the date/timestamp string value to be parsed
options
Object optional Name Type Description fieldType
String optional The type of the string to parse. Either "date" (default) or "timestamp".
dateType
String optional The type of the return object. Either "ecma" (default) or "moment"
Returns:
Type Description Date | Moment the Date object Examples
var fileContext = documentsContext.getFileContext(); var date = documents.sdk.utils.parseDate(fileContext.getFileFieldValue("date"), {fieldType: "date", dateType: "moment"}); //check if the date is in the future if (date.isAfter(moment())) { //change the field background color to red if the date is in the future documentsContext.getFileContext().setFileFieldBgColor("date", "#FF0000"); }
var fileContext = documentsContext.getFileContext(); var date = documents.sdk.utils.parseDate(fileContext.getFileFieldValue("date"), {fieldType: "date", dateType: "ecma"}); //check if the date is in the future if (new Date() - date < 0) { //change the field background color to red if the date is in the future documentsContext.getFileContext().setFileFieldBgColor("date", "#FF0000"); }
var fileContext = documentsContext.getFileContext(); var timestamp = documents.sdk.utils.parseDate(fileContext.getFileFieldValue("timestamp"), {fieldType: "timestamp", dateType: "moment"}); //check if the timestamp is between 8:00 and 18:00 if (!timestamp.isBetween(moment('08:00', 'hh:mm'), moment('18:00', 'hh:mm'), null, "[]")) { //change the field background color to red if the time is not between 8:00 and 18:00 documentsContext.getFileContext().setFileFieldBgColor("timestamp", "#FF0000"); }
var fileContext = documentsContext.getFileContext(); var timestamp = documents.sdk.utils.parseDate(fileContext.getFileFieldValue("timestamp"), {fieldType: "timestamp", dateType: "ecma"}); //check if the timestamp is between 8:00 and 18:00 if (!(timestamp.getHours() >= 8 && timestamp.getHours()< 18 || timestamp.getHours() === 18 && timestamp.getMinutes() === 0)) { //change the field background color to red if the time is not between 8:00 and 18:00 documentsContext.getFileContext().setFileFieldBgColor("timestamp", "#FF0000"); }
-
staticdocuments.sdk.utils.parseNumber(value, decimalSeparator, groupingSeparator){Number}
-
Parses a number string and returns it as number.
If any of the optionaldecimalSeparator
orgroupingSeparator
parameters is not set, this function will automatically use the default value of the current user locale configured in the Documents Manager.Name Type Description value
String the number string value to be parsed
decimalSeparator
String optional the decimal separator character
groupingSeparator
String optional the grouping separator character
Returns:
Type Description Number the parsed number value Examples
documents.sdk.utils.parseNumber("1.910,96", ",", "."); // 1910.96
documents.sdk.utils.parseNumber("1.910,96"); // 1910.96