Conditional Table Level Script?

This question has suggested answer(s)

Greetings sagacious ones.

I'm looking for advice on creating a table level script that uses conditional logic.

The goal:

If Program 6h is selected, set Program cost to $8,000. 

If Program 7h is selected, set Program cost to $10,000.

If Program 8h is selected, set Program cost to $5,000

(and so on).

I have been able to set the program cost to $8,000 using the below logic, but it is setting it to $8,000 as long as there is ANY value in the pccl_program field. 

I am looking for advice on the syntax for both making the pccl_progcost field sensitive to what's been specified in pccl_program, and advice on how to add in conditions.

Here's what is setting pccl_progcost to $8,000 as long as there is a value in pccl_program:


function InsertRecord()

{

// Handle insert record actions here

}


function PostInsertRecord()

{

// Handle post insert record actions here

}


function UpdateRecord()
{
if((Values('pccl_program')!=null)&&(Values('pccl_program')!=undefined)&&(Values('pccl_program')!='6h'))
{

// Handle update record actions here

Values('pccl_progcost') = '8000';
}
}


function DeleteRecord()

{

// Handle delete record actions here

}

www.dquest.com

@DataQuestHello

All Replies
  • Arline

    You'll need to play with a switch statement.  Something like this

    var pccl_program = Values('pccl_program')

    switch (pccl_program)

    {

    case '6h' :

    Values('pccl_procost')='8000';

    break;

    case '7h' :

    Values('pccl_procost')='10000';

    break;

    case '8h' :

    Values('pccl_procost')='5000';

    break;

    default :

    Values('pccl_procost')='8000';

    }


  • Jeff,

    You're the best. Thanks for sharing this.

    Using 'switch' is new to me so thanks for the guidance.

    I've got it working just fine for the update records.

    One other question, related to TLS in general. I'd like to expand the functionality of this script to also work when the record is first inserted. I've tried editing the script a bit and I'm thinking I need to remove the requirement that the field not be NULL or undefined in order to trigger the insert script. I removed that but I'm not seeing the second field respond to the value in the variable. Any advice on what I might be missing?

    I built out the script so now I have 2 fields responding to the original value. Here's what I'm working with now:

    function InsertRecord()

    {

     // Handle insert record actions here

    var pccl_program = Values('pccl_program');

    var pccl_programhrs = Values('pccl_programhrs');

    switch (pccl_program)

    {

    case '1' :

    Values('pccl_progcost')='2500';

    Values('pccl_programhrs')=4;

    break;

    case '2' :

    Values('pccl_progcost')='3500';

    Values('pccl_programhrs')=6;

    break;

    case '3' :

    Values('pccl_progcost')='5500';

    Values('pccl_programhrs')=10;

    break;

    case '6h' :

    Values('pccl_progcost')='8000';

    Values('pccl_programhrs')=15;

    break;

    case '6s' :

    Values('pccl_progcost')='10000';

    Values('pccl_programhrs')=20;

    break;

    case '12s' :

    Values('pccl_progcost')='15000';

    Values('pccl_programhrs')=30;

    break;

    case 'Custom' :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    break;

    case 'Embark' :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    break;

    default :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    }

    }

    function PostInsertRecord()

    {

     // Handle post insert record actions here

    var pccl_program = Values('pccl_program');

    var pccl_programhrs = Values('pccl_programhrs');

    switch (pccl_program)

    {

    case '1' :

    Values('pccl_progcost')='2500';

    Values('pccl_programhrs')=4;

    break;

    case '2' :

    Values('pccl_progcost')='3500';

    Values('pccl_programhrs')=6;

    break;

    case '3' :

    Values('pccl_progcost')='5500';

    Values('pccl_programhrs')=10;

    break;

    case '6h' :

    Values('pccl_progcost')='8000';

    Values('pccl_programhrs')=15;

    break;

    case '6s' :

    Values('pccl_progcost')='10000';

    Values('pccl_programhrs')=20;

    break;

    case '12s' :

    Values('pccl_progcost')='15000';

    Values('pccl_programhrs')=30;

    break;

    case 'Custom' :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    break;

    case 'Embark' :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    break;

    default :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    }

    }

    function UpdateRecord()

    {

    if((Values('pccl_program')!=null)&&(Values('pccl_program')!=undefined))

    // Handle update record actions here

    var pccl_program = Values('pccl_program');

    var pccl_programhrs = Values('pccl_programhrs');

    switch (pccl_program)

    {

    case '1' :

    Values('pccl_progcost')='2500';

    Values('pccl_programhrs')=4;

    break;

    case '2' :

    Values('pccl_progcost')='3500';

    Values('pccl_programhrs')=6;

    break;

    case '3' :

    Values('pccl_progcost')='5500';

    Values('pccl_programhrs')=10;

    break;

    case '6h' :

    Values('pccl_progcost')='8000';

    Values('pccl_programhrs')=15;

    break;

    case '6s' :

    Values('pccl_progcost')='10000';

    Values('pccl_programhrs')=20;

    break;

    case '12s' :

    Values('pccl_progcost')='15000';

    Values('pccl_programhrs')=30;

    break;

    case 'Custom' :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    break;

    case 'Embark' :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    break;

    default :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    }

    }

    function DeleteRecord()

    {

     // Handle delete record actions here

    }

    www.dquest.com

    @DataQuestHello

  • Arline

    I am sorry but I don't see what you're trying to do.

    Try and narrow things down so that you are only using the minimum code that will demonstrate what you are trying to do.


  • Got it- ok, that might have been overkill.

    So the immediate goal is to ALSO apply some behavior to the record when it's being created/inserted.

    Right now, the record is responding to our 'switch' script only when the record is updated.

    I was thinking that by removing the condition that the field not be null or undefined would help, because when the record is first inserted it starts with a null value.

    I removed this snippet:

    if((Values('pccl_program')!=null)&&(Values('pccl_program')!=undefined))

    And here's the pertinent snippet:

    function InsertRecord()

    {

    // Handle insert record actions here

    var pccl_program = Values('pccl_program');

    var pccl_programhrs = Values('pccl_programhrs');

    switch (pccl_program)

    {

    case '1' :

    Values('pccl_progcost')='2500';

    Values('pccl_programhrs')=4;

    break;

    case '2' :

    Values('pccl_progcost')='3500';

    Values('pccl_programhrs')=6;

    break;

    default :

    Values('pccl_progcost')='0';

    Values('pccl_programhrs')=0;

    }

    }

    www.dquest.com

    @DataQuestHello

  •  did that clarification make sense?

    www.dquest.com

    @DataQuestHello

  • Arline

    If this is for a custom entity then you'll need to use the postinsertrecord event function.  The insertrecord event function is really only used by Entity Level Scripts.

    Have a play with the postinsertrecord event function to see whether you can read the inbound data and use Values("xxxxx")='yyyy' to set field values.