CustomFields.ReadCustomFieldsByMdPropUids2 方法
取得其中公式語言相關的格式都是根據指定的自訂欄位的唯一識別碼,通用權限的自訂欄位定義。
命名空間: WebSvcCustomFields
組件: ProjectServerServices (在 ProjectServerServices.dll 中)
語法
'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/CustomFields/ReadCustomFieldsByMdPropUids2", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/CustomFields/", _
ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/CustomFields/", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadCustomFieldsByMdPropUids2 ( _
md_prop_uids As Guid(), _
autoCheckOut As Boolean _
) As CustomFieldDataSet
'用途
Dim instance As CustomFields
Dim md_prop_uids As Guid()
Dim autoCheckOut As Boolean
Dim returnValue As CustomFieldDataSet
returnValue = instance.ReadCustomFieldsByMdPropUids2(md_prop_uids, _
autoCheckOut)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/CustomFields/ReadCustomFieldsByMdPropUids2", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/CustomFields/",
ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/CustomFields/",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public CustomFieldDataSet ReadCustomFieldsByMdPropUids2(
Guid[] md_prop_uids,
bool autoCheckOut
)
參數
md_prop_uids
類型:[]自訂欄位 Guid 的陣列
autoCheckOut
類型:System.Boolean如果true,取出的自訂欄位進行修改。
傳回值
類型:WebSvcCustomFields.CustomFieldDataSet
備註
Project Server 2010新方法。如果自訂欄位或圖形標記由公式計算, ReadCustomFieldsByMdPropUids2方法會將傳回CustomFieldDataSet中的公式轉換成取決於在 [地區及語言選項控制台執行 Project Server 的電腦中指定的地區設定的格式。相較之下, ReadCustomFieldsByMdPropUids方法會傳回CustomFieldDataSet公式會與地區設定無關的位置。
Project Server 權限
權限 |
描述 |
---|---|
可讓使用者在載入企業通用範本。通用權限。 |
|
可讓使用者修改企業自訂欄位與查閱表格值的定義。通用權限。 |
|
可讓使用者修改企業自訂欄位與查閱表格值的定義。通用權限。 |
|
可讓使用者將新專案新增至 Project Server 資料庫。通用權限。 |
|
可讓使用者存取資源中心以及檢視資源分派資料。通用權限。 |
|
可讓使用者存取 [資源計劃] 頁面。通用權限。 |
|
可讓使用者建立產品組合分析。通用權限。 |
|
範例
下列範例會讀取自訂欄位中,會使用ReadCustomFieldsByMdPropUids和ReadCustomFieldsByMdPropUids2 ,然後寫入customFieldDS內容CustomFieldDataSet.xml和CustomFieldDataSet2.xml,分別。除了MD_PROP_FORMULA,這兩種方法會傳回相同的資料。
For more information, including a procedure that shows how to use Project Web App and Project Professional 2010 with the same formula, see Using Formulas and Graphical Indicators with Custom Fields.
會傳回由ReadCustomFieldsByMdPropUids公式欄位MD_PROP_FORMULA而定的地區設定 (伺服器] 與 [專案安裝的語言)..and 是下列程式碼所示。
<MD_PROP_FORMULA>Switch(Not ([MSPJ188743724] >= #01/01/1984# And [MSPJ188743724] < #01/01/2050#),
"No Baseline", ([MSPJ188743685] + 1) / ([MSPJ188743686] + 1) > 1.2, "Overbudget by 20% or more",
([MSPJ188743685] + 1) / ([MSPJ188743686] + 1) > 1, "Overbudget", True, "Under budget")</MD_PROP_FORMULA>
傳回ReadCustomFieldsByMdPropUids2 (如下列程式碼所示) 公式欄位MD_PROP_FORMULA的地區設定無關。在不同的語言安裝運作方式的相同方式。有鑑於此, ReadCustomFieldsByMdPropUids2方法,則高於ReadCustomFieldsByMdPropUids方法。
<MD_PROP_FORMULA><MD_PROP_FORMULA>Switch(Not ([Baseline Estimated Finish] >= #1/1/1984# And [Baseline Estimated Finish] < #1/1/2050#),
"No Baseline", ([Cost] + 1) / ([Baseline Cost] + 1) > 1.2, "Overbudget by 20% or more",
([Cost] + 1) / ([Baseline Cost] + 1) > 1, "Overbudget", True, "Under budget")</MD_PROP_FORMULA>
此範例會修改公式和呼叫UpdateCustomFields2方法,以更新的自訂欄位,,然後將更新的資料集寫入UpdatedCustomFieldData.xml的此外,
它會呼叫CheckInCustomFields之後修改存回的自訂欄位,並呼叫CheckOutCustomFields來取出的自訂欄位,然後再修改它們。
The example uses the SvcCustomFields namespace in the ProjectServerServices.dll proxy assembly. The ConfigClientEndpoints method and the SetClientEndpoints method use an app.config file for setting the WCF binding, behavior, and endpoint. For information about creating a PSI proxy assembly and an app.config file, see Prerequisites for WCF-Based Code Samples.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ServiceModel;
namespace Microsoft.SDK.Project.Samples.TestCustomFields
{
class CustomFields
{
private static SvcCustomFields.CustomFieldsClient customFieldClient;
private static SvcResource.ResourceClient resourceClient;
private const string RES_ENDPOINT = "basicHttp_Resource";
private const string CUST_ENDPOINT = "basicHttp_CustomFields";
private const string OUTPUT_FILES = @"C:\Projects\Samples\Output\";
private static string outFilePathCustomFields;
private static string outFilePathCustomFields2;
private static string outFilePathCustomFields3;
static void Main(string[] args)
{
try
{
Guid[] customFieldID = new Guid[1];
customFieldID[0] = new Guid("4bfa524a-ce48-4a31-a2d6-5e8baa6c9d29");
ConfigClientEndpoints(CUST_ENDPOINT);
SetClientEndpoints(RES_ENDPOINT);
// If directory does not exist, create it.
if (!Directory.Exists(OUTPUT_FILES))
{
Directory.CreateDirectory(OUTPUT_FILES);
}
// Assign the path where the output XML file will be saved.
outFilePathCustomFields = OUTPUT_FILES + "CustomFieldData.xml";
outFilePathCustomFields2 = OUTPUT_FILES + "CustomFieldData2.xml";
outFilePathCustomFields3 = OUTPUT_FILES + "UpdatedCustomFieldData.xml";
// Create a custom fields dataset.
SvcCustomFields.CustomFieldDataSet customFieldDS =
new SvcCustomFields.CustomFieldDataSet();
// Read the custom fields data by using ReadCustomFieldsByMdPropUids.
customFieldDS = customFieldClient.ReadCustomFieldsByMdPropUids(
new Guid[] { customFieldID[0] }, false);
// Write the dataset to an XML file
customFieldDS.WriteXml(outFilePathCustomFields);
Console.WriteLine("\nSee XML output of the CustomFieldDataSet at {0}",
outFilePathCustomFields);
// Read the custom fields data by using ReadCustomFieldsByMdPropUids2.
customFieldDS = customFieldClient.ReadCustomFieldsByMdPropUids2(
new Guid[] { customFieldID[0] }, false);
// Write the dataset to an XML file.
customFieldDS.WriteXml(outFilePathCustomFields2);
bool checkedOut = false;
// Get the ID of the user.
Guid me = resourceClient.GetCurrentUserUid();
// Check whether the custom field to be updated is checked out.
foreach (SvcCustomFields.CustomFieldDataSet.CustomFieldsRow custRow in customFieldDS.CustomFields)
{
if (custRow.MD_PROP_UID.ToString() == customFieldID[0].ToString())
{
if (custRow.IsNull("MD_PROP_CHECKOUTBY")) // If the custom field is not checked out.
{
// Check out the custom field.
customFieldClient.CheckOutCustomFields(new Guid[] { custRow.MD_PROP_UID });
checkedOut = true;
Console.WriteLine("Custom field checked out.....");
break;
}
else
{
// Check whether the custom field is checked out by you.
if (custRow.MD_PROP_CHECKOUTBY == me)
{
checkedOut = true;
Console.WriteLine("The custom field is already checked out by you");
break;
}
else
{
// The custom field is checked out by some other user.
checkedOut = false;
Console.WriteLine("This custom field has already been checked out");
Console.ReadLine();
break;
}
}
}
}
if (checkedOut)
{
// Modify the formula field of the custom field.
// Type the following statement in a single line.
customFieldDS.CustomFields[0].MD_PROP_FORMULA =
"Switch(Not ([Baseline Estimated Finish] >= #1/1/1984# And [Baseline Estimated Finish] < #1/1/2050#),
\"No Baseline\", ([Cost] + 1) / ([Baseline Cost] + 1) > 1.5, \"Overbudget by 50% or more\",
([Cost] + 1) / ([Baseline Cost] + 1) > 1, \"Overbudget\", True, \"Under budget\")";
// Update the dataset.
customFieldClient.UpdateCustomFields2(customFieldDS, false, false);
customFieldDS.WriteXml(outFilePathCustomFields3);
// Write the custom field data to an XML file.
Console.WriteLine("\nSee XML output of the CustomFieldDataSet at {0}",
outFilePathCustomFields3);
// Check in the custom field.
customFieldClient.CheckInCustomFields(new Guid[] { customFieldID[0] }, false);
}
}
catch (CommunicationException e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\n***System.ServiceModel.CommunicationException:");
Console.WriteLine(e.ToString());
Console.ResetColor();
}
finally
{
Console.Write("\r\n\r\nPress any key....");
Console.ReadKey();
}
}
// Configure the custom field client endpoints.
public static void ConfigClientEndpoints(string endpt)
{
customFieldClient = new SvcCustomFields.CustomFieldsClient(endpt);
}
// Configure the resource client endpoints.
public static void SetClientEndpoints(string ept)
{
resourceClient = new SvcResource.ResourceClient(ept);
}
}
}
更新的資料集,以修改後的公式欄位MD_PROP_FORMULA中,會寫入UpdatedCustomFieldData.xml ,而且是下列程式碼所示。
<?xml version="1.0" standalone="yes"?>
<CustomFieldDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/CustomFieldDataSet/">
<CustomFields>
<MD_PROP_UID>4bfa524a-ce48-4a31-a2d6-5e8baa6c9d29</MD_PROP_UID>
<MD_PROP_ID>188776464</MD_PROP_ID>
<MD_PROP_UID_SECONDARY>64546b89-9a2a-49d8-b3ce-190119a3c562</MD_PROP_UID_SECONDARY> <MD_PROP_ID_SECONDARY>255885317</MD_PROP_ID_SECONDARY>
<MD_ENT_TYPE_UID>ebad93e7-2149-410d-9a39-a8680738329d</MD_ENT_TYPE_UID>
<MD_PROP_NAME>Budget Indicator</MD_PROP_NAME>
<MD_PROP_IS_WORKFLOW_CONTROLLED>false</MD_PROP_IS_WORKFLOW_CONTROLLED>
<MD_PROP_IS_REQUIRED>false</MD_PROP_IS_REQUIRED>
<MD_AGGREGATION_TYPE_ENUM>9</MD_AGGREGATION_TYPE_ENUM>
<MD_PROP_TYPE_ENUM>21</MD_PROP_TYPE_ENUM>
<MD_PROP_IS_MULTILINE_TEXT>false</MD_PROP_IS_MULTILINE_TEXT>
<MD_PROP_DESCRIPTION>Test for graphical indicator example in SDK</MD_PROP_DESCRIPTION>
<MD_PROP_MAX_VALUES>1</MD_PROP_MAX_VALUES>
<MD_PROP_FORMULA>Switch(Not ([Baseline Estimated Finish] >= #1/1/1984# And [Baseline Estimated Finish] < #1/1/2050#),
"No Baseline", ([Cost] + 1) / ([Baseline Cost] + 1) > 1.5, "Overbudget by 50% or more",
([Cost] + 1) / ([Baseline Cost] + 1) > 1, "Overbudget", True, "Under budget")</MD_PROP_FORMULA>
<MD_PROP_GRAPHICAL_INDICATOR>[[==No baseline][5]][[==Overbudget by 50% or more][3]]
[[==Overbudget][2]][[==Under budget][1]]</MD_PROP_GRAPHICAL_INDICATOR>
<MD_PROP_SUMM_GRAPHICAL_INDICATOR>[[==No baseline][5]][[==Overbudget by 50% or more][3]]
[[==Overbudget][2]][[==Under budget][1]]</MD_PROP_SUMM_GRAPHICAL_INDICATOR>
<MD_PROP_PROJ_SUMM_GRAPHICAL_INDICATOR>[[==No baseline][5]][[==Overbudget by 50% or more][3]]
[[==Overbudget][2]][[==Under budget][1]]</MD_PROP_PROJ_SUMM_GRAPHICAL_INDICATOR>
<MD_PROP_GRAPHICAL_INDICATOR_TOOLTIP>false</MD_PROP_GRAPHICAL_INDICATOR_TOOLTIP>
<MD_PROP_ROLLDOWN_TO_ASSN>false</MD_PROP_ROLLDOWN_TO_ASSN>
<MD_PROP_COPY_ON_REASSIGNMENT>false</MD_PROP_COPY_ON_REASSIGNMENT>
<MD_PROP_CHECKOUTDATE>2010-02-08T10:57:21.21-08:00</MD_PROP_CHECKOUTDATE>
<MOD_DATE>2010-02-08T11:12:40.78-08:00</MOD_DATE>
</CustomFields>
</CustomFieldDataSet>