Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create a CF with the contained properties of the given entity type
- function createCF(properties, entityType) {
- var projContext = PS.ProjectContext.get_current();
- var customFields = projContext.get_customFields();
- var cfInfo = new PS.CustomFieldCreationInformation();
- cfInfo.set_name(properties.Name);
- cfInfo.set_description(properties.Description);
- cfInfo.set_fieldType(properties.FieldType);
- cfInfo.set_entityType(entityType);
- cfInfo.set_id(properties.Id);
- cfInfo.set_isEditableInVisibility(properties.IsEditableInVisibility);
- cfInfo.set_isMultilineText(properties.IsMultilineText);
- cfInfo.set_isRequired(properties.IsRequired);
- cfInfo.set_isWorkflowControlled(properties.IsWorkflowControlled);
- cfInfo.set_formula(properties.Formula);
- cfInfo.set_lookupAllowMultiSelect(properties.LookupAllowMultiSelect);
- cfInfo.set_lookupDefaultValue(properties.LookupDefaultValue);
- if (!!properties.LookupTable) {
- // Lookup table field not handled
- }
- var newCF = customFields.add(cfInfo);
- newCF.set_rollsDownToAssignments(properties.RollsDownToAssignments);
- newCF.set_rollupType(properties.RollupType);
- customFields.update();
- projContext.executeQueryAsync(Function.createDelegate(this, function () {
- var row = getRowWithName(properties.Name, entityType);
- //updateRowPublishStatus(row, "Ok", properties.ResultMsg);
- $.event.trigger("customFieldCreated", { Name: properties.Name, Entity: entityType, result: true });
- }), Function.createDelegate(this, function () {
- var row = getRowWithName(properties.Name, entityType);
- // Check if this is a Shadowed UID, if so retry with new UID
- if (arguments[1].get_errorValue() === "CustomFieldInvalidUID") {
- properties.Id = guid();
- properties.ResultMsg = warningCFnewUID;
- dataView.getItem(row).Id = properties.Id;
- dataView.refresh();
- grid.render();
- createCF.call(this, properties, entityType);
- return;
- }
- if (arguments[1].get_errorValue() === "CustomFieldFormulaContainsInvalidFieldReference") {
- //updateRowPublishStatus(row, "Error", errorCFformulaInvField);
- $.event.trigger("customFieldCreated", { Name: properties.Name, Entity: entityType, result: false, retryable: true });
- return;
- }
- //updateRowPublishStatus(row, "Error", arguments[1].get_errorValue());
- $.event.trigger("customFieldCreated", { Name: properties.Name, Entity: entityType, result: false });
- }));
- }
Add Comment
Please, Sign In to add comment