Edits history of script submission #20440 for ' Add Summary Fields (smartsheet)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Add Summary Fields
     * Creates one or more summary fields for the specified sheet.
     */
    export async function main(
      auth: Smartsheet,
      sheetId: string,
      renameIfConflict: string | undefined,
      body: {
        contactOptions?: { email?: string; name?: string }[];
        format?: string;
        formula?: string;
        hyperlink?: {
          reportId?: number;
          sheetId?: number;
          sightId?: number;
          url?: string;
        };
        image?: { altText?: string; height?: number; id?: string; width?: number };
        index?: number;
        locked?: false | true;
        objectValue?:
          | { objectType?: "ABSTRACT_DATETIME"; value?: string }
          | { objectType?: "CHECKBOX"; value?: false | true }
          | {
              objectType?: "CONTACT";
              email?: string;
              name?: string;
              imageId?: string;
            }
          | { objectType?: "DATE"; value?: string }
          | { objectType?: "DATETIME"; value?: string }
          | { objectType?: "DURATION"; days?: number }
          | {
              objectType?: "MULTI_CONTACT";
              value?: {
                objectType?: "CONTACT";
                email?: string;
                name?: string;
                imageId?: string;
              }[];
            }
          | { objectType?: "MULTI_PICKLIST"; value?: string[] }
          | {
              objectType?: "PREDECESSOR_LIST";
              predecessors?: {
                rowId?: number;
                type?: "FF" | "FS" | "SF" | "SS";
                inCriticalPath?: false | true;
                invalid?: false | true;
                lag?: {
                  days?: number;
                  elapsed?: false | true;
                  hours?: number;
                  milliseconds?: number;
                  minutes?: number;
                  negative?: false | true;
                  objectType?: "DURATION";
                  seconds?: number;
                  weeks?: number;
                };
                rowNumber?: number;
              }[];
            };
        options?: string[];
        symbol?: string;
        title?: string;
        type?:
          | "ABSTRACT_DATETIME"
          | "CHECKBOX"
          | "DATE"
          | "DATETIME"
          | "DURATION"
          | "MULTI_PICKLIST"
          | "CONTACT_LIST"
          | "MULTI_CONTACT_LIST"
          | "PICKLIST"
          | "PREDECESSOR"
          | "TEXT_NUMBER";
        validation?: false | true;
      }[],
    ) {
      const url = new URL(
        `${auth.baseUrl}/sheets/${sheetId}/summary/fields`,
      );
      for (const [k, v] of [["renameIfConflict", renameIfConflict]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago