Home: Perl Programming Help: Intermediate:
Make One Field Required based On Selection from Another Field



nickreidy
New User

Oct 2, 2017, 9:57 AM


Views: 9173
Make One Field Required based On Selection from Another Field

How to Make a Field Required based on A Selection from a Different Field

I have 2 fields. One is called request type, the other is part ordered date Request type is a drop down list, part ordered date is a date field

When a user selects from Request Type the value of Parts Request, how do I now make the Parts Ordered field required?

I can not for the life of me figure this out.


Laurent_R
Veteran / Moderator

Oct 2, 2017, 10:03 AM


Views: 9172
Re: [nickreidy] Make One Field Required based On Selection from Another Field

To me, the question is incomprehensible. Where dou you have two fields? In a Perl data structure within your program (say an array or a hash, or a combination thereof)? In an input file? If in an input file, then what kind of format?

Please give more details, or show some code, or both.


nickreidy
New User

Oct 2, 2017, 10:10 AM


Views: 9171
Re: [nickreidy] Make One Field Required based On Selection from Another Field

We use Perl for scripting of a proprietary system.

I have a field that is labeled Request_Type and has multiple choices. When the choice of "Parts Request" is selected, I would like to make another field named Part_Ordered_Date required.

This is a proprietary help desk system and all of the people that created it are gone. I am no Perl expert, but can write in SQL.

I tried if, then, else statements from SQL but it doesn't work.


FishMonger
Veteran / Moderator

Oct 2, 2017, 10:54 AM


Views: 9169
Re: [nickreidy] Make One Field Required based On Selection from Another Field

Is this a web app?

Can you post the code?


ogit2
Novice

Oct 4, 2017, 4:34 AM


Views: 9133
Re: [nickreidy] Make One Field Required based On Selection from Another Field

Hi

As per previous posts, there is not much info to go on. If you are using a web page, then the way forward would be JavaScript not Perl with onChange function changing properties of part ordered date or when submitting, checking the date and request type and posting a message.

Hope this helps.


(This post was edited by ogit2 on Oct 6, 2017, 2:55 AM)


nickreidy
New User

Oct 4, 2017, 6:51 AM


Views: 9130
Re: [ogit2] Make One Field Required based On Selection from Another Field

Thank you everyone, but it was figured out:

my $request_type_value = $entity->GetFieldStringValue($fieldname);
if( ${request_type} ne "" ){
$entity->SetFieldRequirednessForCurrentAction( "Part_Ordered_Date", $CQPerlExt::CQ_MANDATORY );
}
else {
$entity->SetFieldRequirednessForCurrentAction( "Part_Ordered_Date", $CQPerlExt::CQ_OPTIONAL );
}