Auto-Populate with delivery informations

MaxGanzert
Kilo Contributor

We have the demand to move the "request for", "Delivery informations" and "Special instructions" from the checkout widget onto the form itself for our hardware catalogue.  The delivery informations should be automatically populated with:

"Company"

"Street"
"City" + "ZIP"
"Country"
from the user data, who is ordering.
Currently I do it with this catalog client script, but sadly it does not run:

// Retrieve the user's record from the User [sys_user] table and query for g_user
    var userGr = new GlideRecord('sys_user');
    userGr.addQuery('sys_id', g_user.userID);
    userGr.query(myCallBack);

    //define the callback function
    function myCallBack(gr) {
        if (gr.next()) {
            alert(userGr.country);
        }
    }

    if (userGr.next()) {
        // Retrieve the company name and location data from the user record
        var companyName = userGr.getElement('company').getDisplayValue();
        var street = userGr.getElement('street').getDisplayValue();
        var zipCode = userGr.getElement('zip').getDisplayValue();
        var city = userGr.getElement('city').getDisplayValue();
        var country = userGr.getElement('country').getDisplayValue();

        // Construct the delivery address using the retrieved data
        var deliveryAddress = (companyName || '') + '\n' +
            (street || '') + '\n' +
            (zipCode || '') + ' ' +
            (city || '') + '\n' +
            (country || '');

        // Set the value of the "delivery_address" field
        g_form.setValue('delivery_address', deliveryAddress);
    } else {
        g_form.setValue('delivery_address', "No matches after query");
    }
0 REPLIES 0