0

Im programatically approving approval task. Im using this code:

ht[SPBuiltInFieldId.Completed] = "TRUE";
ht["Completed"] = "TRUE";
ht[SPBuiltInFieldId.PercentComplete] = 1.0f;
ht["PercentComplete"] = 1.0f;
ht["Status"] = "Completed";
ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)openTask.Web.Language, false), Strings.WorkflowStatusCompleted, new object[0]);
ht[SPBuiltInFieldId.FormData] = SPWorkflowStatus.Completed;
ht[SPBuiltInFieldId.WorkflowOutcome] = "Schváleno"//Approved in czech language;
ht[SPBuiltInFieldId.TaskStatus] = "Schváleno";//Approved in czech language;
ht["TaskStatus"] = "Schváleno";//Approved in czech language;

Ref: Approve a SharePoint workflow task using SharePoint Web Services / Object Model

Everything works but i think this code is uggly:

first of all I dont understand why is nessery to define value for SPBuiltInFieldId.TaskStatus and "TaskStatus"? But when I remove "TaskStatus" task is not approved. I see that SPBuiltInFieldId.TaskStatus is secial id of field but why it not write value to "TaskStatus" field?

My second bigger problem is why I need to put value of TaskStatus in sharepoint instalation language string form. As you can see my sharepoint is localized to czech language. But when I will move to another sharepoint instance (slovak, english...) this code stop to work correctily.

Is there any option to get language string of text "Approved" in sharepoint installation language? something like SPBuiltInFieldId.TaskStatus?

Community
  • 1
  • 1
PeterMacko
  • 882
  • 1
  • 10
  • 15

1 Answers1

1

You can use localization functionality of SharePoint. So replace all "Completed" and "Schváleno" by

SPUtility.GetLocalizedString("$Resources:core,Tasks_Completed", null, web.Language)

There are two important parts of the code:

  1. "$Resources,core,Tasks_Completed" - refers to the core.resx file in Resources SharePoint folder. It contains many system resources strings used by SharePoint internally. E.g. task statuses as in this case.
  2. web.Language - values in choices (task status) are determined by the language of the web. In UI (e.g. setting button text) you should use:

    SPUtility.GetLocalizedString("$Resources:core,cui_ButListFormSave", null, (uint)System.Threading.Thread.CurrentThread.CurrentUICulture.LCID)

    as this uses language of current user because SP utilize impersonation by default.

Jan Vanek
  • 889
  • 1
  • 6
  • 8