Microsoft365 List Get (for paging)

Microsoft365 リスト取得(ページング時)

Get Microsoft365 list data if there is a next page. Acquired data is append to a string multi-line data item.

Auto Step icon
Configs for this Auto Step
conf_OAuth2
A: OAuth 2.0 Setting *
conf_nextLink
B: next link URL from before *
conf_list
C: Data List (update) *
conf_keyName
D: Data Key Name *#{EL}
conf_nextLink2
E: next link URL for after (update)
conf_log
X: Access Log (update)
Script (click to open)


// Get Microsoft365 Group Member List via Microsoft Graph API v1.0 (ver. 202211)
// (c) 2022, Questetra, Inc. (the MIT License)

//// == 工程コンフィグの参照 / Config Retrieving ==
const oauth2  = configs.get( "conf_OAuth2" ) + "";

const nextLink = engine.findDataByNumber(configs.get( "conf_nextLink" )) + "";
const keyName = configs.get( "conf_keyName" ) + "";

const dataId_list     = configs.get( "conf_list" );
const dataId_nextLink2 = configs.get( "conf_nextLink2" );
const dataId_log      = configs.get( "conf_log" );

//// == 演算 / Calculating ==
let accessLog = "";
let uri = nextLink;
let response = httpClient.begin()
  .authSetting( oauth2 )
  .get( uri );
accessLog += "---GET request--- " + response.getStatusCode() + "\n";
accessLog += response.getResponseAsString() + "\n";


//// == ワークフローデータへの代入 / Data Updating ==
const status = response.getStatusCode();

if( status >= 300 ){
  engine.log(accessLog);
  throw `Failed in DELETE request. status: ${status}`;
} else {
  const jsonObj = JSON.parse( response.getResponseAsString() );
  const values = jsonObj.value;
  //既存リストを取得して追記
  let list = engine.findDataByNumber( dataId_list) + "";
  for (let i = 0; i < values.length; i++) {
    let value = values[i];
//    list += value.mail + "\n";
    list += value[keyName] + "\n";
  }
  engine.setDataByNumber( dataId_list, list );

  if( dataId_nextLink2 !== "" ){
    engine.setDataByNumber( dataId_nextLink2, jsonObj['@odata.nextLink'] );
  }

}
if( dataId_log !== "" ){
  engine.setDataByNumber( dataId_log, accessLog );
}

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

Capture

%d bloggers like this: