0

I'm trying to create a new lookup table in Project Server 2016 on prem from a SP hosted application using JSOM.

I have the following code:

private createLookupTables(): ng.IPromise<any> {
        var deferred = this.$q.defer();

        var projectContext = PS.ProjectContext.get_current();
        var lookupTables = projectContext.get_lookupTables();
        projectContext.load(lookupTables);

        projectContext.executeQueryAsync((sender, args) => {
            lookupTables.add(this.createLookupTable('54085ae0-d844-4c50-8835-c07e069cace2', 'test29'));
            lookupTables.update();
            projectContext.load(lookupTables);
            projectContext.executeQueryAsync((sender, args) => {
                deferred.resolve();
            }, (sender, args) => {
                deferred.reject(args.get_message());
            });
        }, (sender, args) => {
            deferred.reject(args.get_message());
        });

        return deferred.promise;
    }

    private createLookupTable(id: string, name: string): any {
        var lookupTableCreationInfo = new PS.LookupTableCreationInformation()
        lookupTableCreationInfo.set_id(id);
        lookupTableCreationInfo.set_name(name);
        lookupTableCreationInfo.set_sortOrder(0);

        var lookupMask = new PS.LookupMask();
        lookupMask.set_length(0);
        lookupMask.set_maskType(3);
        lookupMask.set_separator('.');
        lookupTableCreationInfo.set_masks(lookupMask);

        var entries = [];

        var ltEntry = new PS.LookupEntryCreationInformation();
        ltEntry.set_description("descr");
        ltEntry.set_sortIndex(1);
        ltEntry.set_id("7a6a9f6c-0987-4e72-887a-7cee1fdf9809")
        ltEntry.set_parentId(null);

        var ltValue = new PS.LookupEntryValue();
        ltValue.set_textValue("test");

        ltEntry.set_value(ltValue);
        entries.push(ltEntry);

        lookupTableCreationInfo.set_entries(entries);

        return lookupTableCreationInfo;
    }

What am I missing or doing wrong? Currently, the second executeQueryAsync call goes on the fail function with the error message being "Unknown error". Any ideas?

0

After a bit more digging I found the issue, the set_masks method expects a list of masks as a parameter, so the fix was: lookupTableCreationInfo.set_masks(lookupMask) -> lookupTableCreationInfo.set_masks([lookupMask])

The lack of documentation at it again...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.