VTAP API:使開發人員能夠無縫簡化、檢索和創新

VTAP API 提供了強大的功能,使開發人員能夠有效率地檢索、更新和管理數據,並無縫執行各種操作。

在本期中,我們為您提供以下範例:

  • 使用刷新記錄
  • 重新載入清單視圖
  • 檢索當前登入使用者的使用者角色詳細信息
  • 檢索特定使用者的角色詳細信息

使用 VTAP API 刷新記錄以自動重新載入數據

使用 POST 或 PUT 方法更新記錄詳細資訊時,變更不會自動顯示在前端。這是因為這些方法在伺服器端更新數據,但前端不會自動取得最新數據,除非明確指示這樣做。為了確保更新的詳細資訊反映在前端,需要重新載入頁面。

我們可以使用 VTAP API 動態刷新記錄,而無需手動重新載入頁面。

API: VTAP.Detail.RefreshRecord(); 

示例:


  

VTAP.Api.Put('records', {

module : ‘module_name’, 

id : ‘record_id’, 

field_name : ‘field_value’,

}, (error, response) => {                    

 If (response) {                        

VTAP.Detail.RefreshRecord();                         VTAP.Utility.ShowSuccessNotification("Record Updated Successfully.");                    

}

 });


  

VTAP.Api.Put('records', {

module : ‘module_name’, 

id : ‘record_id’, 

field_name : ‘field_value’,

}, (error, response) => {                    

 If (response) {                        

VTAP.Detail.RefreshRecord();                         VTAP.Utility.ShowSuccessNotification("Record Updated Successfully.");                    

}

 });

文件參考連結: https://vtap.vtiger.com/platform/resources/vtap-js.html#vtap-detail-refreshrecord

使用 VTAP API 重新載入清單視圖

當透過 VTAP API 從清單檢視介面建立新記錄時,清單檢視不會自動刷新以顯示新新增的記錄。相反,用戶必須手動重新加載頁面才能查看最新數據。

VTAP API 動態刷新清單視圖,無需重新載入手動頁面。

API: VTAP.List.Reload();

示例:


  

VTAP.Api.Post('records', {

module : 'Contacts', 

firstname : 'John',

lastname : 'Wick', 

'email' : '[email protected]'

}, (error, response) => {

     If (response) {                        

VTAP.Utility.ShowSuccessNotification("Record Created Successfully.");  

VTAP.List.Reload();                  

}

});


  

VTAP.Api.Post('records', {

module : 'Contacts', 

firstname : 'John',

lastname : 'Wick', 

'email' : '[email protected]'

}, (error, response) => {

     If (response) {                        

VTAP.Utility.ShowSuccessNotification("Record Created Successfully.");  

VTAP.List.Reload();                  

}

});

文件參考連結: https://vtap.vtiger.com/platform/resources/vtap-js.html#reload

使用 VTAP API 檢索當前登入使用者的使用者角色詳細信息

VTAP API 可用於檢索目前登入使用者的詳細資訊。此 API 檢索使用者詳細信息,例如個人詳細資訊、偏好或系統相關資料。

在該 API 傳回的資訊中,特別注意使用者的角色詳細資訊。 

透過使用此 API,開發人員可以無縫整合使用者特定的功能,並確保基於使用者角色的正確授權和個人化體驗。

API網址: “我”

示例:


  

VTAP.Api.Get('me', {

'module': 'Users'

}, (error, response) => {

If (response) {

const roleInfo = response.roleid;

         console.log(roleInfo.id); // Logs the role ID

         console.log(roleInfo.label); // Logs the role name

}

});


  

VTAP.Api.Get('me', {

'module': 'Users'

}, (error, response) => {

If (response) {

const roleInfo = response.roleid;

         console.log(roleInfo.id); // Logs the role ID

         console.log(roleInfo.label); // Logs the role name

}

});

使用 VTAP API 檢索特定使用者的角色詳細信息

您可以透過提供使用者 ID 作為參數,使用 VTAP API 檢索特定使用者的角色資訊。

示例:


  

VTAP.Api.Get('records', {

'module': 'Users',

‘Id’: ‘user_id’

}, (error, response) => {

If (response) {

const roleInfo = response.roleid;

         console.log(roleInfo.id); // Logs the role ID

         console.log(roleInfo.label); // Logs the role name

}

});


  

VTAP.Api.Get('records', {

'module': 'Users',

‘Id’: ‘user_id’

}, (error, response) => {

If (response) {

const roleInfo = response.roleid;

         console.log(roleInfo.id); // Logs the role ID

         console.log(roleInfo.label); // Logs the role name

}

});

 
 

註冊以接收最新更新!