Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. // Create a CF with the contained properties of the given entity type
  2. function createCF(properties, entityType) {
  3. var projContext = PS.ProjectContext.get_current();
  4. var customFields = projContext.get_customFields();
  5.  
  6. var cfInfo = new PS.CustomFieldCreationInformation();
  7. cfInfo.set_name(properties.Name);
  8. cfInfo.set_description(properties.Description);
  9. cfInfo.set_fieldType(properties.FieldType);
  10.  
  11. cfInfo.set_entityType(entityType);
  12.  
  13. cfInfo.set_id(properties.Id);
  14.  
  15. cfInfo.set_isEditableInVisibility(properties.IsEditableInVisibility);
  16. cfInfo.set_isMultilineText(properties.IsMultilineText);
  17. cfInfo.set_isRequired(properties.IsRequired);
  18. cfInfo.set_isWorkflowControlled(properties.IsWorkflowControlled);
  19. cfInfo.set_formula(properties.Formula);
  20.  
  21. cfInfo.set_lookupAllowMultiSelect(properties.LookupAllowMultiSelect);
  22. cfInfo.set_lookupDefaultValue(properties.LookupDefaultValue);
  23.  
  24. if (!!properties.LookupTable) {
  25. // Lookup table field not handled
  26. }
  27.  
  28. var newCF = customFields.add(cfInfo);
  29. newCF.set_rollsDownToAssignments(properties.RollsDownToAssignments);
  30. newCF.set_rollupType(properties.RollupType);
  31.  
  32. customFields.update();
  33.  
  34. projContext.executeQueryAsync(Function.createDelegate(this, function () {
  35. var row = getRowWithName(properties.Name, entityType);
  36. //updateRowPublishStatus(row, "Ok", properties.ResultMsg);
  37. $.event.trigger("customFieldCreated", { Name: properties.Name, Entity: entityType, result: true });
  38. }), Function.createDelegate(this, function () {
  39. var row = getRowWithName(properties.Name, entityType);
  40.  
  41. // Check if this is a Shadowed UID, if so retry with new UID
  42. if (arguments[1].get_errorValue() === "CustomFieldInvalidUID") {
  43. properties.Id = guid();
  44. properties.ResultMsg = warningCFnewUID;
  45. dataView.getItem(row).Id = properties.Id;
  46.  
  47. dataView.refresh();
  48. grid.render();
  49.  
  50. createCF.call(this, properties, entityType);
  51. return;
  52. }
  53.  
  54. if (arguments[1].get_errorValue() === "CustomFieldFormulaContainsInvalidFieldReference") {
  55. //updateRowPublishStatus(row, "Error", errorCFformulaInvField);
  56. $.event.trigger("customFieldCreated", { Name: properties.Name, Entity: entityType, result: false, retryable: true });
  57. return;
  58. }
  59.  
  60. //updateRowPublishStatus(row, "Error", arguments[1].get_errorValue());
  61. $.event.trigger("customFieldCreated", { Name: properties.Name, Entity: entityType, result: false });
  62. }));
  63. }
Add Comment
Please, Sign In to add comment