Custom SAM License Metric using Resource Value for more than one product

Christina Guidr
Tera Contributor

I am working with some of our IBM Mainframe products which all have the same calculation needed based on raw data entry.  I successfully created the code in a custom license metric to do the calculation for one test product.  What I want to  know is, if it is possible to use the same calculation and metric for more than one product.  Instead of passing a sys_id of the RV entry as the sample code suggests I tried querying the RV table for all the Resource Value records with a specific name - however it is returning the same calculation for both even though each units Consumed is different:

 

Setup:

 

1. Custom Metric called "Mainframe VU" - queries the RV table for entries with this as the name, then grabs the units_consumed and goes through and if/than/else statement to do the proper calculation.

2. Created two entitlements and two RV entries for different products.  RV entry 1 has 4 as the units_consumed and RV entry 2 has 67

 

When I run reconciliation it shows the same usage in the workspace for both.  I want to try to avoid having to create four separate custom metrics when the calculation is all the same, just not sure how to accomplish this.

4 REPLIES 4

Tom Boudreau
ServiceNow Employee
ServiceNow Employee

I want to help investigate this... You have the logic in the custom License Metric - looking up the RV's data by name and calculating based on that? Would you be willing to share your script so we can jointly check the logic? 

Christina Guidr
Tera Contributor

Thank you for reaching out, I appreciate it.  I think that was what I was trying - figuring out which entitlement it was processing and then trying to use that to find the corresponding resource value record - I can't find my code from before I created separate ones per product - but talking about again I made another attempt this morning  - but now it doesn't seem to be getting into the custom metric code at all - its returning 0 for required licenses for both:

 

getRightsForResourceValue();
function getRightsForResourceValue(){
   
    var rightsForResourceValue = -1;

    var entitlementModel = current.entitlementModel; //this was the new thing I tried this morning

    gs.info('Entitlement Model: '+entitlementModel);

    var resourceValueRecord = new GlideRecord('samp_sw_resource_value');

    resourceValueRecord.addQuery('software_model',entitlementModel);
    resourceValueRecord.query();

    // query the resource value record for the entity
    while (resourceValueRecord.next()){
        // get the raw Units Consumed from the Resource Value Entry
        var resourceValue = resourceValueRecord.getValue('units_consumed');

        if (resourceValue < 4){ //From 1 to 3 MSUs, 1 VU per MSU
            var rvCalc = resourceValue;
        }else if (resourceValue < 46){ //From 4 to 45 MSUs, 3 VUs plus 0.45 VUs per MSU above 3
            var msuOver = resourceValue - 3;
            var rvCalc = 3 + (msuOver * 0.45);
        }else if (resourceValue < 176){ //From 46 to 175 MSUs, 22 VUs plus 0.36 VUs per MSU above 45
            var msuOver = resourceValue - 45;
            var rvCalc = 22 + (msuOver * 0.36)
        } else if (resourceValue < 316){ //From 176 to 315 MSUs, 69 VUs plus 0.27 VUs per MSU above 175
            var msuOver = resourceValue - 175;
            var rvCalc = 69 + (msuOver * 0.27);
        } else { //For more than 315 MSUs, 107 VUs plus 0.20 VUs per MSU above 315
            var msuOver = resourceValue - 315;
            var rvCalc = 107 + (msuOver * 0.20);
        }

    }

    rightsForResourceValue = Math.round(rvCalc);
    return rightsForResourceValue;
}
 
Testing with IBM Fault Analyzer and Debug Tool products

Christina Guidr
Tera Contributor

This is what I am using when doing separate ones - not sure how to get the info of the entitlement it is processing to know which RV record to get:

 

function getRightsForResourceValue(){
   
    var rightsForResourceValue = -1;
    var resourceValueRecord = new GlideRecord('samp_sw_resource_value');

    resourceValueRecord.addQuery('name','Fault Analyzer VU');
    resourceValueRecord.query();

    // query the resource value record for the entity
    while (resourceValueRecord.next()){
        // get the raw Units Consumed from the Resource Value Entry
        var resourceValue = resourceValueRecord.getValue('units_consumed');

        if (resourceValue < 4){ //From 1 to 3 MSUs, 1 VU per MSU
            var rvCalc = resourceValue;
        }else if (resourceValue < 46){ //From 4 to 45 MSUs, 3 VUs plus 0.45 VUs per MSU above 3
            var msuOver = resourceValue - 3;
            var rvCalc = 3 + (msuOver * 0.45);
        }else if (resourceValue < 176){ //From 46 to 175 MSUs, 22 VUs plus 0.36 VUs per MSU above 45
            var msuOver = resourceValue - 45;
            var rvCalc = 22 + (msuOver * 0.36)
        } else if (resourceValue < 316){ //From 176 to 315 MSUs, 69 VUs plus 0.27 VUs per MSU above 175
            var msuOver = resourceValue - 175;
            var rvCalc = 69 + (msuOver * 0.27);
        } else { //For more than 315 MSUs, 107 VUs plus 0.20 VUs per MSU above 315
            var msuOver = resourceValue - 315;
            var rvCalc = 107 + (msuOver * 0.20);
        }

    }

    rightsForResourceValue = Math.round(rvCalc);
    return rightsForResourceValue;
}

Christina Guidr
Tera Contributor

I figured it out - just you responding pushed me to dig again and I figured it out 🙂  For anyone else here - don't discount and wipe out the sample code immediately:

 

function getRightsForResourceValue(){
    var rightsForResourceValue = -1;
    var resourceValueRecord = new GlideRecord('samp_sw_resource_value');

    // query the resource value record for the entity
    if(resourceValueRecord.get(entity)){