Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private async addCol(fieldName, guid): Promise<any> {
- const digestCache: IDigestCache = this.context.serviceScope.consume(DigestCache.serviceKey);
- digestCache.fetchDigest(this.context.pageContext.web.serverRelativeUrl).then((digest: string): void => {
- let obj = {};
- if (fieldName == "Full Address") {
- obj = "{ '__metadata': { 'type': 'SP.FieldText' }, 'FieldTypeKind': 2,'Title': 'Full Address'}";
- }
- if (fieldName == "Description") {
- obj = "{ '__metadata': { 'type': 'SP.FieldText' }, 'FieldTypeKind': 2,'Title': 'Description' }";
- }
- if (fieldName == "Location") {
- obj = "{ '__metadata': { 'type': 'SP.Field' }, 'FieldTypeKind': 31, 'Title': 'Location' }"
- }
- console.log("Post data: ");
- console.log(obj);
- $.post({
- url: this.context.pageContext.site.serverRelativeUrl + "/_api/web/lists(guid'" + guid + "')/fields",
- type: "POST",
- data: obj,
- headers: {
- "accept": "application/json;odata=verbose",
- "content-type": "application/json;odata=verbose",
- "X-RequestDigest": digest,
- },
- success: function (data) {
- //console.log("done");
- //console.log(data)
- console.log("added: " + fieldName);
- },
- error: function (response) {
- console.log(response.responseText);
- }
- });
- });
- }
- {"error":{"code":"-2147023746, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The specified program requires a newer version of Windows. (Exception from HRESULT: 0x8007047E)"}}}
Add Comment
Please, Sign In to add comment