GlideDateTime API in UI Builder

Wayne Richmond
Tera Guru

I'm new to UI Builder and still struggling with some concepts. 

I want a Dropdown that contains the next 14 days. I thought the following script used in the Item panel would work, however, I don't get any results when click the Dropdown field.

 

WayneRichmond_0-1668437664021.png

 

function evaluateProperty({
    api,
    helpers
}) {
    var dateArr = [];
    var daysToInclude = 14;
    var i = 0;
    var body = {};
    do {
        var gdt = new GlideDateTime();
        gdt.addDaysLocalTime(i)
        body.id = 'date' + i;
        body.label = gdt.getLocalDate().toString();
        body.value = gdt.getLocalDate().toString();
        var parsedJSON = JSON.stringify(body)
        dateArr.push(parsedJSON);
        i++;
    } while (i < daysToInclude)
    return ("[" + dateArr + "]");
}

In a background script, the output seems fine, and when the result is copy pasted into the JSON field in the 'Use static input' option, it renders fine. However, the script editor seems to suggest that using the GlideDateTime() API isn't valid:

WayneRichmond_1-1668437814274.png

 

Am I doing this right? 

3 REPLIES 3

Michael Fry1
Kilo Patron

You need to create a Data Resource first. You can add one by clicking the +Add in the upper right corner:

Screen Shot 2022-11-14 at 12.18.19 PM.png

Then go to your configuration field and type @. and you should get choices to pull from your data resources:

Screen Shot 2022-11-14 at 12.18.08 PM.png

Hi Michael, I don't see how a Data Resource would help me. I'm not getting the data from anywhere. I just need the Dropdown populated with the next 14 dates. If this was the classic environment, I'd use the g_form.addOption and an array of dates to populate it. 

Oh, ok. If it's a dropdown, you can configure that in the desktop UI. That doesn't need to be done in UIB.