Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

See below for an XML example of a custom settings data. In this example, settings for the Leave Request process gets stored in domain database and its data is enclosed between <LRDictionary> tags as an arbitrary choice. It includes leave type definitions, their localization data and leave allowance calculation script as javascript code. A settings screen designed in this process loads this XML data and lets users to modify it depending on their needs, which makes this process considerably dynamic and flexible.

...

languagexml
titleSettings Data
collapsetrue

...

 

Code Block
languagexml
titleSettings Data
collapsetrue
<LRDictionary>
  <Definitions>
    <HRGroup Caption="Designer Specialist">439c9457-297e-47b4-b002-0e82ae1c94d0</HRGroup>
    <HRManager Caption="None"/>
    <LeaveTypes>
      <LeaveType>
        <Name>Annual</Name>
        <Code>A</Code>
        <SubLeaveTypes/>
        <Name_tr>Yıllık</Name_tr>
        <IncludeOnCalculation>True</IncludeOnCalculation>
        <HasSubTypes>false</HasSubTypes>
      </LeaveType>
      <LeaveType>
        <Name>Excuse</Name>
        <Code>E</Code>
        <SubLeaveTypes>
          <SubLeaveType>
            <Id>ac9572db-7045-4a37-a170-1781d56483d3</Id>
            <Name>Sickness</Name>
            <Name_tr>Hastalık</Name_tr>
          </SubLeaveType>
          <SubLeaveType>
            <Id>b2caff73-f308-4b01-979c-321dcb123056</Id>
            <Name>Paternity</Name>
            <Name_tr>Babalık</Name_tr>
          </SubLeaveType>
          <SubLeaveType>
            <Id>23cc603f-d037-4acc-90c9-8dc26aefb05a</Id>
            <Name>Death</Name>
            <Name_tr>Vefat</Name_tr>
          </SubLeaveType>
          <SubLeaveType>
            <Id>bc1f4fbc-1b81-4e92-9daa-b91ca39af77a</Id>
            <Name>Other</Name>
            <Name_tr>Diğer</Name_tr>
          </SubLeaveType>
        </SubLeaveTypes>
        <Name_tr>Mazeret</Name_tr>
        <IncludeOnCalculation/>
        <HasSubTypes>true</HasSubTypes>
      </LeaveType>
    </LeaveTypes>
    <Calculation>var today;
$Calendar2.GetToday('', function(newDate) {
    today = newDate;
});

var results = $Database.Get({
    Parameters: {
        TargetSchema: 'HR',
        TargetTable: 'Employee'
    },
    Columns: [{
            Name: 'Id'
        },
        {
            Name: 'StartDate'
        },
        {
            Name: 'LastAllowanceCalcDate'
        },
        {
            Name: 'RegistryNumber'
        }
    ],
    Where: {
        Criteria: [{
                Name: 'LastAllowanceCalcDate',
                Value: today,
                Comparison: 'LessThanOrEqualTo',
                Condition: 'Or'
            },
            {
                Name: 'LastAllowanceCalcDate',
                Value: null,
                Comparison: 'Equals'
            }
        ]
    }
});

var tempDate = DateTimeOffset.parse('2007.01.01');

console.warn('Script Calculation Started');

results.Each(function() {
    if ((this.RegistryNumber != null) &amp;&amp; (this.StartDate != null)) {

        var tickerDate;
				
        if  (this.LastAllowanceCalcDate == null) {
            this.LastAllowanceCalcDate = this.StartDate;
			console.warn("LastAllowanceCalcDate not found, using StartDate");
        }
				
        console.warn('Calculation started for ' + this.RegistryNumber + " - " + this.LastAllowanceCalcDate );
		
		console.warn('Last Calculation Date is ' + this.LastAllowanceCalcDate.getFullYear() + '.' + this.LastAllowanceCalcDate.getMonth() + '.' + this.LastAllowanceCalcDate.getDate());

        tickerDate = this.LastAllowanceCalcDate;
			
        while (tickerDate &lt; today) {
		
			console.warn('Ticker Date is ' + tickerDate.getFullYear() + '.' + tickerDate.getMonth() + '.' + tickerDate.getDate());
			
            var allowance = 0;

            if (this.StartDate.getMonth() == tickerDate.getMonth()) {

                var diff = tickerDate.getFullYear() - this.StartDate.getFullYear();

                if (this.RegistryNumber == '151917') {
                    allowance = 29;
                } else {
                    if (this.StartDate &lt; tempDate) {
                        if (diff &gt;= 0 &amp;&amp; diff &lt;= 5) {
                            allowance = 17;
                        } else if (diff &gt; 5 &amp;&amp; diff &lt;= 10) {
                            allowance = 22;
                        } else if (diff &gt; 10) {
                            allowance = 27;
                        }
                    } else {
                        if (diff &gt;= 0 &amp;&amp; diff &lt;= 5) {
                            allowance = 17;
                        } else if (diff &gt; 5 &amp;&amp; diff &lt;= 14) {
                            allowance = 22;
                        } else if (diff &gt; 14) {
                            allowance = 26;
                        }
                    }
                }

                if (allowance &gt;= 0) {     
                    var strDate = tickerDate.getFullYear() + '.' + tickerDate.getMonth() + '.' + this.StartDate.getDate();
                    var allowedDate = DateTimeOffset.parse(tickerDate.getFullYear() + '.' + tickerDate.getMonth() + '.' + this.StartDate.getDate());
                    var allowanceForCurrentYear =  allowance - Math.round((allowance * (allowedDate.getMonth() / 12)));
                    InsertNewAllowance(this.Id, allowance, strDate, allowanceForCurrentYear);
                }
            }

            $Calendar2.GetStandardCalendar().AddMonths(tickerDate, 1, function(newDate) {
                tickerDate = newDate;
            });
        }

        this.LastAllowanceCalcDate = today;

        console.warn('Calculation ended for ' + this.RegistryNumber);

    }else{
	console.warn("RegistryNumber Number or Employee Start Date not found");
	}

});

console.log('Script Calculation Ended');

results.Save();


function InsertNewAllowance(employeeId, daysGained, strAllowedDate, daysGainedForCurrentYear) {
        
    var allowedDate = DateTimeOffset.parse(strAllowedDate);    

	var leaveResults = $Database.Get({
		Parameters: {
			TargetSchema: 'HR',
			TargetTable: 'LeaveAllowance'
		},
		Columns: [{
				Name: 'Id'
			}
		],
		Where: {
			Criteria: [{
					Name: 'AllowedDate',
					Value: allowedDate,
					Comparison: 'Equals'
				},
				{
					Name: 'Employee',
					Value: employeeId,
					Comparison: 'Equals'
				}
			]
		}
	});
	
	if(leaveResults.RowCount() &lt;= 0) {
        
        console.warn('New allowance detected for date : ' + strAllowedDate);
        
        var table = $Database.Empty({
            Parameters: {
                TargetSchema: 'HR',
                TargetTable: 'LeaveAllowance'
            }
        });

        table.Add({
            Id: Script.NewId(),
            Employee: employeeId,
            AllowedDate: allowedDate,
            DaysGained: daysGained,
            WorkItemId: $WorkItem.Id,
            FormNo: $Instance.Number,
            DaysGainedForCurrentYear : daysGainedForCurrentYear
        });

        table.Save();    
    }
}</Calculation>
    <Manager2Approval/>
    <SecondManagerApprovalExcluded/>
    <DayCountForWeek>5</DayCountForWeek>
  </Definitions>
</LRDictionary>

In this example, settings for the Leave Request process gets stored in domain database and its data is enclosed between <LRDictionary> tags as an arbitrary choice. It includes leave type definitions, their localization data and leave allowance calculation script as javascript code. A settings screen designed in this process loads this XML data and lets users to modify it depending on their needs, which makes this process considerably dynamic and flexible.