Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * File: \src\AllFt\AllFt_SourceOther_wfInitialize.js
- * Project: mDocs Cloud Solution
- * Created Date: 14.08.2017 07:08:68
- * Author: mitjak
- * Description:
- * -----
- * Last Modified: 08.01.2018
- * Modified By: mitjak
- * -----
- * Copyright (c) 2017 Mikrografija d.o.o.
- */
- // #import "Prototype";
- // #import "AllFtExtendedLib";
- // #import "IncomingInvoiceLib"; // CUSTOM SIMONAV 09-09-2019
- try {
- var docFile = context.file;
- var su = context.getSystemUser();
- var fileType = docFile.getAutoText("%fileType%");// CUSTOM SIMONAV 09-09-2019
- switch(docFile.Source) {
- case "manual":
- break;
- case "eRacun":// CUSTOM START
- case "eracun":
- var hrs = null;
- var organizations = null;
- // Set organization
- docFile.DocumentNumber = "";
- docFile.setFieldAttribute("DocumentNumber", "Value", "");
- var orgTaxNumber = docFile.Contact;
- hrs = new HitResultset("OrganizationalUnit", "TechnicalName!='' AND Enabled='1'", "", ["Id"]);
- for (var hitFile = hrs.first(); hitFile; hitFile = hrs.next()) {
- var organizationalUnitFile = hitFile.getFile();
- if(organizationalUnitFile) {
- if(organizationalUnitFile.CompanyTaxNumber.indexOf(orgTaxNumber)!=-1){
- docFile.setFieldAttribute("OrganizationalUnit", "Value", organizationalUnitFile.TechnicalName);
- docFile.OrganizationalUnit = organizationalUnitFile.TechnicalName;
- //docFile.ConfigRef = docFile.getAutoText("fileType") + "_" + docFile.Organization;
- //docFile.setFieldAttribute("ConfigRef", "Value", docFile.ConfigRef);
- docFile = context.file;
- }
- }
- }
- organizations=null;
- // Set Company
- var comTaxNumber = docFile.TaxNumber;
- hrs = new HitResultset("Account", "TaxNumber~'" + comTaxNumber + "' ", "", ["Id"]);
- //util.out("TaxNumber='" + comTaxNumber + "'");
- //util.out("hrs.size() = " + hrs.size());
- if(hrs.size() > 0) {
- docFile.CompanyNumber = hrs.first().getFile().getAutoText("%id%");
- }
- hrs.dispose();
- hrs = null;
- if(docFile.OrganizationalUnit=="17") {
- docFile.setFieldAttribute("c_SaopTransfer", "Value", 1);
- docFile.c_SaopTransfer = 1;
- }
- docFile.Contact = "";
- docFile.setFieldAttribute("Contact", "Value", "");
- if(!docFile.sync())
- throw docFile.getLastError();
- if(docFile.getAutoText("%fileType%")=="IncomingInvoice") {
- IncomingInvoiceHelper.setDocumentNumber(docFile);
- }
- /*organization = util.getOrganization(docFile);
- if(
- organization &&
- organization != "all"
- ) {
- ConfirmationHelper.setDefaultConfirmationValues(docFile, true);
- ConfirmationHelper.setConfirmationFields(docFile, true);
- } else {*/
- if(fileType == "IncomingInvoice") {
- ConfirmationHelper.setConfirmationFields(docFile, false);
- } else {
- ConfirmationHelper.setConfirmationFields(docFile, true);
- }
- //}
- break;
- case "mScan":
- case "mscan":
- case "TIS":
- case "tis":
- case "import":
- default:
- var organization = util.getOrganization(docFile);
- var configRegExist = docFile.hasField("ConfigRef");
- var confirmationEnabled = (util.getModuleConfigAttribute(docFile.getAutoText("fileType"), "ConfirmationEnabled") == 1);
- /*if(
- organization &&
- organization != "all"
- ) {*/
- /*if(configRegExist) {
- docFile.ConfigRef = docFile.getAutoText("fileType") + "_" + organization;
- docFile.setFieldAttribute("ConfigRef", "Value", docFile.ConfigRef);
- docFile = context.file;
- }*/
- /*if(confirmationEnabled) {
- ConfirmationHelper.setDefaultConfirmationValues(docFile, true);
- ConfirmationHelper.setConfirmationFields(docFile, true);
- }
- } else {*/
- /*if(configRegExist) {
- docFile.ConfigRef = docFile.getAutoText("fileType");
- docFile.setFieldAttribute("ConfigRef", "Value", docFile.ConfigRef);
- docFile = context.file;
- }*/
- if(fileType == "IncomingInvoice") {
- ConfirmationHelper.setConfirmationFields(docFile, false);
- } else {
- ConfirmationHelper.setConfirmationFields(docFile, true);
- }
- //}
- if(confirmationEnabled) {
- ConfirmationHelper.setConfirmer(docFile, "Confirmer1");
- docFile.sync();
- }
- break; // CUSTOM END
- }
- ModuleHelper.repairFields(docFile);
- var messageCommentField = util.getFileTypeProperty(
- docFile.getAutoText("%fileType%"),
- "$CommentField"
- );
- if(
- util.buildNo >= 2060 &&
- messageCommentField &&
- docFile.hasField(messageCommentField) &&
- docFile[messageCommentField]
- ) {
- try {
- if(
- messageCommentField &&
- //docFile.hasField(messageCommentField) &&
- docFile[messageCommentField] &&
- (
- docFile[messageCommentField].toString().indexOf("{") != 0 ||
- docFile[messageCommentField].toString().indexOf("_$$$_") > 0
- )
- ) {
- var json = {
- fileId: docFile.getAutoText("%id%"),
- messages: [],
- member: []
- };
- var repair = false;
- var indexDollars = docFile[messageCommentField].toString().indexOf("_$$$_");
- if(indexDollars > 0) {
- repair = true;
- docFile[messageCommentField] = JSON.stringify(JSON.parse(docFile[messageCommentField].toString().substring(0, indexDollars)));
- } else if(docFile[messageCommentField].toString().indexOf("{") != 0) {
- repair = true;
- json.messages.push({
- body: docFile[messageCommentField].toString(),
- recipients: [],
- id: "",
- author: (su ? su.login : ""),
- authorLabel: (su ? su.firstName + " " + su.lastName : ""),
- timestamp: ((new Date).getTime()/1000)
- });
- docFile[messageCommentField] = JSON.stringify(json);
- }
- if(repair) {
- docFile.setFieldAttribute(messageCommentField, "ShortValue", docFile[messageCommentField]);
- docFile.setFieldAttribute(messageCommentField, "Value", docFile[messageCommentField]);
- docFile.sync();
- }
- }
- } catch(eComment) {
- util.errorLog(eComment);
- }
- }
- Helper.executeCustomScript(docFile);
- } catch (e) {
- util.errorLog(e);
- //context.errorMessage = e;
- //return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement