Location Update in Zoho Desk Against Picklist field

PHOTO EMBED

Tue Jan 28 2025 19:10:42 GMT+0000 (Coordinated Universal Time)

Saved by @Hassnain_Abbas

string standalone.TestDeskLocationUpdates()
{
Page_Number = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52};
Locations_list = List();
Location_Names = List();
// List to store "Location_Name_For_Desk" field values
total_records_count = 0;
// Counter to track total records
// --------->>>>Fetch Records and "Location_Name_For_Desk" Data <<<<<----------------
for each  no in Page_Number
{
	// info no;
	LocationsRec = zoho.crm.getRecords("Deals",no);
	// Fetch records from each page
	//  Locations_list.addAll(LocationsRec);  // Add all records to the master list
	total_records_count = total_records_count + LocationsRec.size();
	// Loop through each record to extract "Location_Name_For_Desk" field
	for each  rec in LocationsRec
	{
		if(rec.containsKey("Location_Name_For_Desk"))
		{
			// Check if the field exists
			Location_Names.add(rec.get("Location_Name_For_Desk"));
		}
	}
	// Break if fewer than 200 records are fetched, indicating end of available data
	if(LocationsRec.size() <= 199)
	{
		break;
	}
}
//------------Check Dublication------------
Distinct_list = Location_Names.distinct();
// Filtered Data
queryValue = Map();
queryValue.put("defaultValue","-None-");
queryValue.put("allowedValues",Distinct_list.toList());
//----------Authtoken---------------------------------------------------------
Desk_NewAccessTokenRequest = invokeurl
[
	url :"https://accounts.zoho.com/oauth/v2/token?refresh_token=1000.daa4436319a1d3e0bfe78fe3f564a7fa.48b125526495975ac16adf57dfcd592c&client_id=1000.DP7DCNEXQHNJIV58JDKW7UJX0Z5M6R&client_secret=f7266ae45c4cce8c4a6477c4188f1ad89684b15aca&redirect_uri=https://rebiz.com/&grant_type=refresh_token"
	type :POST
];
Desk_NewAccessToken = Desk_NewAccessTokenRequest.get("access_token");
//---------------------------Authtoken---------------------------------------
DeskAccountAuthtoken = Map();
DeskAccountAuthtoken.put("Authorization","Zoho-oauthtoken " + Desk_NewAccessToken + "");
DeskAccountAuthtoken.put("orgId","673553956");
//---------------------------------------------------------------------------
Resp = invokeurl
[
	url :"https://desk.zoho.com/api/v1/layouts/309910000008730384/fields/309910000329061015"
	type :PATCH
	parameters:queryValue + ""
	headers:DeskAccountAuthtoken
];
info Resp;
// Log the total count of records
info "Total Records Count: " + total_records_count;
return "";
//Location_Names.toString();  // Return the list of "Location_Name_For_Desk" values
}
content_copyCOPY