ProductSchedule: SetRates
Can be called to set the rates associated with the product schedule.
Function
Array SetRates(steppedRates)
Parameters
An Array object that contains Stepped Rate objects with Rate & Duration properties. the array must have at least one object. See Example below.
Name | Type | Description |
---|---|---|
Rate | Number | The product rate per minute |
Duration | Number | The duration (seconds) for the rate is applied |
When an empty or invalid object array is given as a parameter, a warning will appear in message viewer and script execution will continue without applying any changes to existing Stepped Rates.
Return Value
None
Example
let productSchedule = GetComponentByNameAndType("ProductSchedule1", "Product Schedule");
// Read the ProfileType.
if (productSchedule.ProfileType === 0)
{
LogDebug("The profile type is uniform.");
}
else if (productSchedule.ProfileType === 1)
{
LogDebug("The profile type is flight.");
}
else if (productSchedule.ProfileType === 2)
{
LogDebug("The profile type is custom.");
}
else if (productSchedule.ProfileType === 3)
{
LogDebug("The profile type is stepped rates.");
}
// Enable the looping of the rates.
productSchedule.Loop = true;
// Disable the looping of the rates.
productSchedule.Loop = false;
// Retrieve the rates from the product schedule.
let rates = productSchedule.GetRates();
// Print the rates.
for (let i = 0; i < rates.length; ++i)
{
LogDebug("Stepped Rate object index "+i+": Rate: " + rates[i].Rate +" Duration: "+ rates[i].Duration );
}
// Add a rate.
rates.push({"Rate": 60, "Duration": 12});
rates.push({"Rate": 80, "Duration": 20});
productSchedule.SetRates(rates);
// Remove an index (0-based) from the rates.
rates.splice(2, 1); // Remove 1 element from the 2nd index.
productSchedule.SetRates(rates);