Catalog Client Script

CesarV_
Tera Contributor

Hi all,

 

I am trying to configure a Date variable on a Catalog Item form so users can only select a date that is at least two weeks out from the current date. Using a Catalog Client Script, I tried scripting this function, which gives me no errors but seems to not change anything on the form. 

 

Can anyone take a look at my script and tell me what I might be doing wrong? 

 

Example: highlighted dates should be grayed out and not selectable:

CesarV__0-1758897188360.png

 

My Script: 

 

function onLoad() {
    var today = new Date();
    var minDate = new Date();
    minDate.setDate(today.getDate() + 14);

    // Format minDate as yyyy-MM-dd
    var yyyy = minDate.getFullYear();
    var mm = String(minDate.getMonth() + 1).padStart(2, '0');
    var dd = String(minDate.getDate()).padStart(2, '0');
    var formattedMinDate = yyyy + '-' + mm + '-' + dd;

    // Set the min attribute on the date input field
    var dateField = g_form.getControl('requested_fulfillment_date');
    if (dateField) {
        dateField.setAttribute('min', formattedMinDate);
    }
}

 

1 ACCEPTED SOLUTION

RaghavSh
Mega Patron

@CesarV_ I believe you dn't need client script in this case, did you try UI policy.

 The condition should be <date variable> "Relative (operator)  after  14 Days from now".

 

Once you select the variable and operator as "relative", you will get other options to select. This way you can achieve this without script login.

 

After the condition, in the run script under "execute if true" , you can throw and alert or clear the field if earlier dat is selected.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

View solution in original post

13 REPLIES 13

Hi @CesarV_ , Hope you are doing well, have you tried the solution I have posted? It worked in my project.

 

If my answer given earlier were helpful then Please Mark this solution as accepted and helpful as it will be helpful for other users as well.
Best Regards.
Saurabh V.

Hi @CesarV_ , Did you try my solution? was it helpful?

 

If my answers given earlier were helpful then Please Mark this solution as accepted and helpful as it will be helpful for other users as well.
Best Regards.
Saurabh V.

@svirkar420 this did not work, unfortunately. 

Hi @CesarV_ , Hope you are doing well, Did you tried implementing my given solution?

If my answers given earlier were helpful then Please Mark this solution as accepted and helpful as it will be helpful for other users as well.
Best Regards.
Saurabh V.