# Remove Information from a Project

The following example shows you how to remove information from a project using Clarity LIMS and API (compatible with v2 r21 and later).

As of Clarity LIMS v5, the term **user-defined field** (UDF) has been replaced with custom field in the user interface. However, the API resource is still called **UDF**.

There are two types of custom fields:

* **Master step fields**—Configured on master steps. Master step fields only apply to the following:
  * The master step on which the fields are configured.
  * The steps derived from those master steps.
* **Global fields**—Configured on entities (eg, submitted sample, derived sample, measurement, etc.). Global fields apply to the entire Clarity LIMS system.

### Prerequisites

Before you follow the example, make sure that you have the following items:

* A user-defined field (UDF) / custom field named **Objective** is defined for projects.
* A project name that is unique and does not exist in the system.

### Code Example <a href="#example" id="example"></a>

This example does the following actions:

1. POST a new project to the LIMS, with a UDF / custom field value for **Objective**.
2. Remove a child XML node from the parent XML representing the project resource.
3. Update the project resource.

#### Step 1. POST a New Project with a UDF Value for Objective <a href="#step1" id="step1"></a>

First, set up the information required to perform a successful project POST. The project name must be unique.

```
// Determine project list's URI
String projectsListURI = "http://${hostname}/api/v2/projects"
 
def builder = new StreamingMarkupBuilder()
builder.encoding = "UTF-8"
openDate = "2017-08-24"
 
// Build a new project using Markup Builder
def projectDoc = builder.bind {
    mkp.xmlDeclaration()
    mkp.declareNamespace(prj: 'http://genologics.com/ri/project')
    mkp.declareNamespace(udf: 'http://genologics.com/ri/userdefined')
    'prj:project'{
        'name'(projectName)
        'open-date'(openDate)
        'researcher'(uri:"http://${hostname}/api/v2/researchers/1")
        'udf:field'(name:"Objective","To test httpPOST")
    }
}
// Post the new project
def projectNode = GLSRestApiUtils.xmlStringToNode(projectDoc.toString())
projectNode = GLSRestApiUtils.httpPOST(projectNode, projectsListURI, username, password)
println GLSRestApiUtils.nodeToXmlString(projectNode)
```

The **projectNode** should contain the response XML from the POST and resemble the following output:

```
<prj:project xmlns:prj="http://genologics.com/ri/project" uri="http://yourIPaddress/api/v2/projects/WOR512" limsid="WOR512">
  <name>httpPOST Project then remove nodes</name>
  <open-date>2017-08-24</open-date>
  <researcher uri="http://yourIPaddress/api/v2/researchers/1"/>
  <udf:field xmlns:udf="http://genologics.com/ri/userdefined" type="String" name="Objective">To test httpPOST</udf:field>
  <permissions uri="http://yourIPaddress/api/v2/permissions/projects/WOR512"/>
</prj:project>
```

#### Step 2. Remove Child XML Node from Parent XML Node <a href="#step2" id="step2"></a>

The following code removes the child XML node **\<udf:field>** from the parent XML node **\<prj:project>**:

```
// If projectNode is parentNode, remove the child udf:field
projectNode?.children()?.remove(projectNode.'udf:field'[0])
 
// Print the node that will be updated
println GLSRestApiUtils.nodeToXmlString(projectNode)
```

If multiple nodes of the same type exist, \[0] is the first item in this list of same typed nodes (eg, 0 contains 1st item, 1 contains 2nd item, 2 contains 3rd item, and so on).

To remove the 14th udf:field, you would use projectNode?.children()?.remove(projectNode.'udf:field'\[13])

### Attachments

RemoveChildNode.groovy:

{% file src="<https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-cad400c12d9045adbab705cb077507bf3183229b%2FRemoveChildNode.groovy?alt=media&token=276ce9c3-e71f-453a-b3fa-9bf52db62ca9>" %}
