サンプルコード例

サンプルコード例

お知らせ:当社は、お客様により充実したサポート情報を迅速に提供するため、本ページのコンテンツは機械翻訳を用いて日本語に翻訳しています。正確かつ最新のサポート情報をご覧いただくには、本内容の英語版を参照してください。

以下は、Zoho Creator の iOS 向け SDK の各種メソッドの使い方を示すコードスニペットです。

FieldAccessPath を構築する

FieldAccessPath を使用すると、対象のフィールドを、対象のフォーム内で参照できます。構築方法は次のように異なります。

通常のフィールドの場合:


FieldAccessPath.項目(linkName: <FieldLinkName>)


複合フィールド内のサブフィールドの場合(例: 名前フィールド内の first_name フィールド、または住所フィールド内の 国 フィールドなど):


FieldAccessPath.compositeField(linkName: <CompositeFieldLinkName>, subFieldLinkName: <SubFieldLinkName>)


サブフォーム内の通常フィールドの場合:

FieldAccessPath.subFormField(linkName: <SubFormLinkName>, entryId: <EntryId>, fieldLinkName: <FieldLinkName>)


サブフォーム内の複合フィールドのサブフィールドの場合:


FieldAccessPath.subFormCompositeField(linkName: <CompositeFieldLinkName>, subFormLinkName: <SubFormLinkName>, entryId: <EntryId>, subFieldLinkName: <SubFieldLinkName>)

 

フォームオブジェクトを取得する

データを追加する際の表示形式でフォームオブジェクトを取得するには、次のようにします。


let formInfo = FormInfo(linkName: <FormLinkName>, displayName: <FormDisplayName>)
ZCFormAPIService.fetch(for: formInfo) { (workFlowChangeSetResult) in
    切り替える workFlowChangeSetResult {
      case .完了(let changeSet)
        let form = changeSet.form
      case .failure(_):
        //Failure
      }
  }


データを編集する際の表示形式でフォームオブジェクトを取得するには、次のようにします。


let formInfo = FormInfo(linkName: <FormLinkName>, displayName: <FormDisplayName>)
ZCFormAPIService.fetch(forRecordID: <RecordId>, reportLinkName: <ReportLinkName>, formInfo: <FormInfo>) { (result) in
      switch workFlowChangeSetResult {
        case .success(let changeSet):
          let form = changeSet.form
        case .failure(_):
          // 失敗
      }
  }

 

フィールドから選択肢を取得する

Zoho Creator では、次のフィールドタイプで選択肢が表示されます:ドロップダウンラジオボタン複数選択チェックボックスルックアップ、「氏名」フィールドの「敬称」サブフィールド、「住所」フィールドの「国」サブフィールドです。必須フィールドの AccessPath を構成するには、このセクションを参照してください。フォームでデータを追加する際に、フィールドに表示される選択肢を取得するには:


// FieldAccessPath の構築方法については参照してください
let fieldAccessPath = FieldAccess.項目(linkName: <ChoiceFieldLinkName>)
ZCFormAPIService.fetchChoices(forSearchString: <SearchString>, of: fieldAccessPath, in: <form>, fromIndex: <FromIndex>) { (result) in
    切り替える result {
      case .完了(let choices):
        // 選択肢
      case .failure(_):
        // 失敗
      }
  }


フォームでレコードを編集する際に、フィールドに表示される選択肢を取得するには:


let fieldAccessPath = FieldAccess.項目(linkName: <ChoiceFieldLinkName>)
ZCFormAPIService.fetchChoices(withRecordID: <データ Id>, forReportLinkName: <ReportLinkName>, forSearchString: <検索する String>, of: fieldAccessPath, in: <form>, fromIndex: <FromInde>) { (result) in
    切り替える result {
      case .完了(let choices):
        //choices
      case .failure(_):
        //failure
      }
  }

 

フォームを送信する

フォームを送信してデータを追加するには:


ZCFormAPIService.送信する(form: <Form>) { (result) in
    切り替える result {
      case .完了(let response):
        //Submit response
      case .failure(let error):
        //Error
    }
  }


フォームを送信してデータを編集するには:


ZCFormAPIService.updateRecord(withRecordID: <recordLinkID>, inReportLinkName: <ReportLinkName>,form: <Form>) { (result) in
    switch result {
      case .success(let response):
        // 応答を送信
      case .failure(let error):
        // エラー
    }
}

 

フィールド値を設定するには

  1. 対象フィールドのAccessPath を作成します。
  2. フォームからフィールドとインデックスを取得します:
    
    <form>.getFieldAndIndex(using: <fieldAccessPath>)
    // (field, index)
    
  3. フィールドの現在値を取得します:
    
    <field>.getValue()
    // InputValues
    
  4. フィールド
    • 以下のフィールドに値を設定するには: 1 行テキストメール数値パーセント小数通貨複数行リッチテキストメモの追加日付日付-時間、または時間フィールド:
      
      InputValues.textFieldValue(fieldValue:<your_input>)
      
    • decision ボックス項目の値を設定するには:
      
      InputValues.decisionFieldValue(fieldValue: <boolean_value>)
      
    • ドロップダウン、ラジオ、ルックアップ(単一選択)、ユーザー、および連携項目の値を設定するには:
      
      if case InputValues.singleSelectChoiceFieldValue(var existingValue) = <field>.getValue() {
         existingValue.selectedChoice = { existingValue.choice から適切な値を選択します }
         let newField = field.setValueFor(value: existingValue) //更新された項目
      }
      
    • チェックボックス、複数選択、またはルックアップ(複数選択)項目の値を設定するには:
      
      if case InputValues.multiSelectChoiceFieldValue(var existingValue) = <field>.getValue() {
         existingValue.selectedChoice = { existingValue.choice から適切な値を選択します }
         let newField = field.setValueFor(value: existingValue) //更新された項目
      }
      
    • 電話番号項目の値を設定するには:
      
      let newField = field.setValueFor(value: InputValues.phoneNumberFieldValue(countryCode:<コード>,number: <PhoneNumber>))
      
    • URL項目の値を設定するには:
      
      let newField = field.setValueFor(value: InputValues.urlFieldValue(url:<url>,title:<title>,linkName:<linkName>))
      
  5. フォームに項目を更新するには:
    
    <form>.setField(updatedField,at: index)
    

メディア項目にファイルをアップロードしてフォームを送信する

画像、ファイルアップロードaudiovideo、または署名項目にファイルをアップロードし、フォームを送信してデータを追加するには:

funcsubmitMediaField(:Data,:String,:String){let=FormInfo(:'<formLinkName>',:'<formDisplayName>',:'<AppLinkName>',:'<AppOwner>',:nil)// フォームを取得ZCFormAPIService.fetch(for:(){in切り替える{case.failure(let):印刷する()case.sucess(let):var=.let=FieldAccessPath.項目(:)//get 項目 値iflet(,)=.getFieldAndIndex(:),caseInputValues.mediaFieldValue(var)=.getValue(){// メディアをアップロードZCFormAPIService.アップロードする(:,:,for:,:){()in切り替える{case.sucess(let):// メディア項目の値を設定.=.iflet=.setValueFor(:.mediaFieldValue(:)){.setField(,:)// フォームを送信ZCFormAPIService.送信する(:){()in切り替える{case.sucess(let):// 完了レスポンス印刷する('完了')case.failure(_):// 失敗印刷する('Failure')}}}case.failure(let):印刷する()}}}}}}


画像、ファイルアップロード、オーディオ、ビデオ、または署名項目にファイルをアップロードし、そのフォームを送信してデータを更新するには、次のようにします。

funcupdateMediaField(:Data,:String,:String,:String){let=FormInfo(:'<formLinkName>',:'<formDisplayName>',:'<AppLinkName>',:'<AppOwner>',:nil)ZCFormAPIService.fetch(:,:,:){in切り替える{case.failure(let):印刷する()case.sucess(let):var=.let=FieldAccessPath.項目(:)iflet(,)=.getFieldAndIndex(:),caseInputValues.mediaFieldValue(var)=.getValue(){// メディアをアップロードするZCFormAPIService.アップロードする(:,:,for:,:){()in切り替える{case.sucess(let):// メディア項目の値を設定.=.iflet=.setValueFor(:.mediaFieldValue(:)){.setField(,:)// データを更新するZCFormAPIService.updateRecord(:,:,:){()in切り替える{case.sucess(let):// 完了レスポンス印刷する('完了')case.failure(_):// 失敗印刷する('Failure')}}}case.failure(let):印刷する()}}}}}}

 

Creator アプリに存在するセクションを取得する


let firstApp = self.appList.applications[0] ZCAPIService.fetchSectionList(for: firstApp, completionHandler: { (result) in
    switch result{
    case .failure(let error):
        // エラーを処理
    case .sucess(let sectionList):        
        // sectionList を処理
        self.sectionList = sectionList
}
})

 

レポートを取得する

let reportInfo = ReportInfo(openUrlInfo: nil, appOwner: '<アプリ所有者>', appLinkName: '<アプリリンク名>', linkName: '<レポートリンク名>', type: .report, appDisplayname: nil, displayName: nil, notificationEnabled: false)
        let config = ListReportAPIConfiguration(fromIndex: 1, limit: 50, moreInfo: ReportAPIConfiguration.init())
        ZCReportAPIService.fetchListReport(for: reportInfo, with: config) { (result) in
            switch result{
            case .failure(let error):
                print(error)
            case .sucess(let listReport):
                // 完了を処理
                print(listReport)
            }
        }

レポート内のデータを処理する

ZCReportAPIService.fetchListReport(for:,:){()inswitch{case.完了(let):guardlet=..first// 最初のデータを返します。(必要に応じて目的のデータを指定することもできます)else{return}do{let=try.
recordValue(for:'<目的のフィールドのフィールドリンク名>')//上で指定したフィールドの表示文字列を返しますlet=..displayValue(for:.)//取得した値をさらに処理する場合切り替える.{case.text(let)://テキスト値フィールド用:単一行、複数行、メール、数値、日付、リッチテキストなど.//文字列を返しますcase.file(let)://メディアフィールド用:ファイルアップロード、画像、音声、動画、署名.//ファイルのURLを返します.//フィールドに関連する追加プロパティを返しますcase.名前(let)://名前フィールド用.//名前フィールドの表示値を返します.//名前フィールドのサブフィールド値(敬称、first_name、last_name、敬称(後置))を返しますcase.住所(let)://住所フィールド用.//住所フィールドの表示値を返します.//住所フィールドのサブフィールド値(address_line_1、address_line_2、district_city、state_province、postal_Code、国)を返します.//利用可能な場合は緯度を返します.//利用可能な場合は経度を返しますcase.phoneNumber(let)://電話番号フィールド用.//電話番号を返しますcase.リンク(let)://リンクフィールド用.//リンクフィールドの表示値を返します.//フィールドに対応するリンクを返しますcase.linkedRecords(let,:let)://[表示するリンク]プロパティが設定されているルックアップまたはサブフォームフィールド用let=.first//最初のレコードを返します(任意のレコードを指定することもできます)?.//レコードの表示文字列を返します?.//レコードのIDを返しますcase.choices(let,:let)://選択フィールド用:ラジオボタン、ドロップダウン、複数選択、チェックボックスlet=.first//最初の選択肢を返します(任意の選択肢を指定することもできます)? .//選択肢の文字列を返しますcase.values(let)://複数選択ルックアップ項目の関連値//ここで 'values' は配列であり、上記のようにさらに処理できますbreak}}catchlet{印刷する('\(recordValueError) データ値の処理中に発生しました')}case.failure(let)://ここでエラーを処理します印刷する('レポートエラーが発生しました: \(エラー)')}}

通知履歴を取得する


func fetchAllNotifications() {
 ZCAPIService.fetchUserInfo {(result) in
  切り替える (result)
   {
   case .完了(let userInfo):
    ZCAPIService.fetchNewNotifications(lastNotificationID: nil, filterUnread: false, filteredApp: nil) { notificationsResult in
      切り替える(notificationsResult)
       {
       case .完了(let notificationList):
        印刷する ('\(notificationList)')
       case .failure(let error):
        印刷する ('\(エラー)')
       }
    }
   case .failure(let error):
    印刷する ('\(エラー)')
  }
 }
}

エンドユーザーが通知をタップしたときにレコード概要を表示する


func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> 無効) {
 if let notificationInfo = response.notification.request.content.userInfo as? [String: Any] {
  if ZCNotificationService.isCreatorServerNotification(notificationInfo: notificationInfo) ==  {
   if let zcNotification = ZCNotificationService.zcNotification(notificationInfo)
   {
    let summaryVC = ZCUIService.getNotificationController(for: zcNotification)
    window?.rootViewController?.present(UINavigationController.init(rootViewController: summaryVC), animated: , completion: nil)
   }
  }
  else
  {
   // Zoho Creator サーバーからの通知ではありません
  }
  completionHandler()
 }
}

通知からレコードのメタデータを取得する


 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> 無効) {
  if let notificationInfo = response.notification.request.content.userInfo as? [String: Any] {
   if ZCNotificationService.isCreatorServerNotification(notificationInfo: notificationInfo) ==  {
    if let zcNotification = ZCNotificationService.zcNotification(notificationInfo) {
     ZCAPIService.fetchNewNotificationRedirectionInfo(notificationID: zcNotification.notificationID, category: zcNotification.category) { result in
      切り替える (result)
       {
       case .完了(let notificationRecordInfo):
        印刷する ('\(notificationRecordInfo)')
       case .failure(let error):
        印刷する ('\(エラー)')
      }
     }
    }
   }
   else
    {
    // Zoho Creator サーバーからのものではありません
    }
   completionHandler()
  }
 } 


    Zoho CRM 管理者向けトレーニング

    「導入したばかりで基本操作や設定に不安がある」、「短期間で集中的に運用開始できる状態にしたい」、「運用を開始しているが再度学び直したい」 といった課題を抱えられているユーザーさまに向けた少人数制のオンライントレーニングです。

    日々の営業活動を効率的に管理し、導入効果を高めるための方法を学びましょう。

    Zoho CRM Training



              Zoho Campaigns Resources

                Zoho WorkDrive Resources




                  • Desk Community Learning Series


                  • Digest


                  • Functions


                  • Meetups


                  • Kbase


                  • Resources


                  • Glossary


                  • Desk Marketplace


                  • MVP Corner


                  • Word of the Day


                  • Ask the Experts









                                  • Related Articles

                                  • サンプルコード例

                                    お知らせ:当社は、お客様により充実したサポート情報を迅速に提供するため、本ページのコンテンツは機械翻訳を用いて日本語に翻訳しています。正確かつ最新のサポート情報をご覧いただくには、本内容の英語版を参照してください。 メモ: Zoho Creator のモバイル SDK は現在ベータ版機能です。本番環境のアプリでは使用しないことをおすすめします。 Java 以下は、Android 向け Zoho Creator SDK の各種メソッドの使用方法を示すコードスニペットです: Creator ...

                                  Resources

                                  Videos

                                  Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                  eBooks

                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                  Webinars

                                  Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                  CRM Tips

                                  Make the most of Zoho CRM with these useful tips.