Expression snippets overview

Modified on Thu, 22 Feb 2024 at 01:45 PM

This can be used to make new Pricing rule expressions, these are meant to be examples.


Value expressions:

  • return context.GetCustomerNumericValue("<some metadata key on the customer>", <some default margin in decmial nr e.g. 0.000000m>);
    • Used to retrieve a numeric value from the customer, can be used to get a margin for example.
  • return context.GetCustomerNumericValue("NCE_Use_Cost") == 1 ? context.GetManufacturerCostPrice().Value : context.GetManufacturerSuggestedRetailPrice().Value;
    • Used in NCE pricing rules, checks whether cost plus model should be used and retrieves prices from the Pricing Sheets in the connector (which are a verson of custom tables).
  • return context.GetCustomerNumericValue("AWSCommittedSpend", 0m) * context.GetCustomerNumericValue("AWSBaseFeePercentage", 0m) / 100;
    • Used to calculate a markup in ANS' environment. Gets two customer numeric values from the customer and uses these to calculate.
  • var amount = context.CurrentSourceItem.Value;

    var minCharge = 0m;
    var step1 = 10000m;
    var step2 = 80000m;
    var step3 = 250000m;

    if (amount <= 0) {
    return 0;
    } else if(amount > 0 && amount <= step1) {
    return 0.1m * amount;
    } else if (amount > step1 && amount <= step2) {
    return (0.1m * step1 + 0.07m * (amount - step1)) > minCharge ? (0.1m * step1 + 0.07m * (amount - step1)) : minCharge;
    } else if (amount > step2 && amount <= step3) {
    return 0.1m * step1 + 0.07m * (step2 - step1) + 0.05m * (amount - step2);
    } else {
    return 0.1m * step1 + 0.07m * (step2 - step1) + 0.05m * (step3 - step2) + 0.03m * (amount - step3);
    }
    • Functions as a ladder rule for adjust percentages. Steps function as thresholds. The first 10000 is uplifted by 10%, then between 10000 and 80000 by 7%, between 80000 and 250000 by 5%, and above 250000 with 3%.
  • return context.GetCustomerNumericValue("Profit", context.CustomTableData.GetSingleValueByQuery("Margin","margin", 0m, "name=="margin"));
    • Retrieves information from a custom table called Margin, in the column called margin.



var amount = context.CurrentSourceItem.Value;
var quantity = context.CurrentSourceItem.Quantity;
var averagePrice = amount/quantity;

var minCharge = 0m;
var step1 = 5m;
var step2 = 10m;
var step3 = 15m;

var discount1=0.05m;
var discount2=0.10m;
var discount3=0.15m;

if (quantity <= 0) {
return 0;
} else if(quantity > 0 && quantity <= step1) {
return averagePrice;
} else if (quantity > step1 && quantity <= step2) {
return (step1*averagePrice + (averagePrice - discount1*averagePrice)* (quantity - step1))/quantity > minCharge ? (step1*averagePrice + (averagePrice - discount1*averagePrice)* (quantity - step1))/quantity : minCharge;
} else if (quantity > step2 && quantity <= step3) {
return (step1*averagePrice + (averagePrice - discount1*averagePrice)* (step2 - step1) + (averagePrice - discount2*averagePrice)* (quantity - step2))/quantity;
} else {
return (step1*averagePrice + + (averagePrice - discount1*averagePrice)* (step2 - step1) + (averagePrice - discount2*averagePrice)* (quantity - step2)+ (averagePrice - discount1*averagePrice)* (step3 - step2)+ (averagePrice - discount3*averagePrice)* (quantity - step3))/quantity;
}


Provides staggered discount for the total sum based on the quantity and discount steps. For the first 5 products, there is no discounts, the next 5 get a 5%, Next 5 - 10%, Next 5 - 15%.


Cost expressions:

  • return context.GetManufacturerCostPrice().Value;
    • Used in NCE pricing rules, retrieves cost price from the Pricing Sheets in the connector (custom table).


Rule condition expressions:

  • return context.GetCustomerStringValue("AWSFee", "").ToLower() == "true";
    • Used to determine whether the rule is carried out for the current customer based on some metadata.
  • string country = context.GetCustomerStringValue("Country", "Nederland"); return country == "Nederland" && context.CustomerCode != "131722 - ADVCENTRAAL - 96"; 
    • Used to determine whether the rule is carried out based on customer metadata and the CustomerCode.
  • string country = context.GetCustomerStringValue("Country", "Nederland"); string vatcode = context.GetCustomerStringValue("VatCode", ""); switch(country){case "Nederland": return false;
    case "België":
    case "Hongarije":
    case "Polen":
    case "Bulgarije":
    case "Ierland":
    case "Portugal":
    case "Cyprus":
    case "Italië":
    case "Roemenië":
    case "Denemarken":
    case "Letland":
    case "Slovenië":
    case "Duitsland":
    case "Litouwen":
    case "Slowakije":
    case "Estland":
    case "Luxemburg":
    case "Spanje":
    case "Finland":
    case "Malta":
    case "Tsjechië":
    case "Frankrijk":
    case "Verenigd Koninkrijk":
    case "Griekenland":
    case "Oostenrijk":
    case "Zweden":
    case "Kroatië": return vatcode != "";
    default: return true;}
    • Used to determine based on a switch case whether this rule can be used.



Item condition expressions:

  • return context.CurrentSourceItem.GetDateValue("PricingDate",System.DateTimeOffset.MaxValue).DateTimeComplete >= new System.DateTime(2023, 11, 01);
    • Can be used to check whether a metadata field on the purchase (current source item) is larger than a certain date.
  • return context.CurrentSourceItem.GetDateValue("CommitmentEndDateTime",System.DateTimeOffset.MaxValue).DateTimeComplete == new System.DateTime(2024, 02, 27, 23, 59, 59) || context.CurrentSourceItem.GetDateValue("CommitmentEndDate",System.DateTimeOffset.MaxValue).DateTimeComplete == new System.DateTime(2024, 02, 27, 23, 59, 59);
    • Can be used to check for a very specific type of metadata.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article