Expand my Community achievements bar.

SOLVED

Need Help with Simple Coding Question (substring or charAt)

Avatar

Level 1

Hello,

I have what I believe to be a simple coding question i was hoping someone could help answer. I know how to do a decent amount of things but am pretty new to Livecycle, and am trying to alter one of our PDF's so that if a certain field has a number beginning with the number 6 a certain button will become visible. I already have a set of code that is controlling the visibility of this button, but I wanted to add this clause to it. Can someone help me do this?

Here is the existing code:

if((QuestionsPage2.COIQuestions.COIYN.rawValue == "1" &&

    QuestionsPage2.EmailButtons.NSFCheck.rawValue == "1") &&

   (QuestionsPage2.ManagerSignature.ManagerDate.rawValue != null &&

    QuestionsPage2.ManagerSignature.ManagerCheckBox.rawValue != null &&

    QuestionsPage2.ManagerSignature.ManagerSignature.rawValue != null))

{

QuestionsPage2.PasswordSection.RiskPassword.presence = "visible";

QuestionsPage2.PasswordSection.PurchUseOnly.presence = "visible";

QuestionsPage2.PasswordSection.HRPassword.presence = "visible";

QuestionsPage2.EmailButtons.EmailContractsAndRisk.presence = "visible";

}

I want to add in the top section to look at the specific field at the first character to see if its a 6 or not. Here is what I have tried to do, but it hasnt worked.

if((QuestionsPage2.COIQuestions.COIYN.rawValue == "1" &&

    QuestionsPage2.EmailButtons.NSFCheck.rawValue == "1" &&

    ContractInfo.AgreementDetails.Org.substring(0,1) != "6" )

The field type I am looking at is a "Numeric Field" field with 4 characters.

Can someone help me fix my code so that this works?

Thanks!!

1 Accepted Solution

Avatar

Correct answer by
Level 10

you don't need to do such a work around, all what you didn't notice is that NumericField is not a string is always a numeric (Number)

so You cannot use substring on a integer or decimal... unless it's a string.. so use the toString() after the .rawValue like this

This should be working.

View solution in original post

4 Replies

Avatar

Level 10

I hope ORG is a field in your form. Try to change you code slightly as below and verifyt the output.

ContractInfo.AgreementDetails.Org.rawValue.substring(0,1) != "6"

Hope this will resolve your issue.

Nith

Avatar

Level 1

Thanks for the reply!

Unfortunately that did not work. I found a work around, doing (ContractInfo.AgreementDetails.Org.rawValue >= 6000 && ContractInfo.AgreementDetails.Org.rawValue <=6999).

I would still like to know why the substring command wasnt working correctly. I have tried many different variations and none of them work.

A crazy work-around I did was this:

var str = ContractInfo.AgreementDetails.Org.rawValue;

TextField1.rawValue = str;

TextField2.rawValue = TextField1.substr(0,1);

TextField2 was indeed correctly populated, but I do not know why i have to go through this crazy work around. Does anyone know why the following doesnt work?

var str = ContractInfo.AgreementDetails.Org.rawValue.substr(0,1)

Avatar

Correct answer by
Level 10

you don't need to do such a work around, all what you didn't notice is that NumericField is not a string is always a numeric (Number)

so You cannot use substring on a integer or decimal... unless it's a string.. so use the toString() after the .rawValue like this

This should be working.

Avatar

Level 1

Thank you so much! Worked perfectly! I thought that there must be something with the coding and that was it!