You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development_server.md
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
+
# Development Server
2
+
1
3
The Functions SDK includes a development server that allows you to run your Functions in your development environment. The server reads Functions from the `environment.yaml` file and makes them available via HTTP endpoints. You can then connect these Functions to your CIM Database Cloud instance using webhooks.
2
4
3
-
This speeds up the development of Functions, because you can instantly test your changes, without deploying them to the cloud infrastructure first.
5
+
This speeds up the development of Functions because you can instantly test your changes without deploying them to the cloud infrastructure first.
4
6
5
7
## Starting the Server
6
8
@@ -16,7 +18,7 @@ You can set the port of the server using the `--port` flag (default is 8000), or
16
18
python -m csfunctions.devserver --port 8080
17
19
```
18
20
19
-
You can set the directory containing the `environment.yaml` file using the `--dir` flag (by default the current working directory is used) or by setting the `CON_DEV_DIR` environment variable:
21
+
You can set the directory containing the `environment.yaml` file using the `--dir` flag (by default, the current working directory is used) or by setting the `CON_DEV_DIR` environment variable:
The development server will automatically restart if you make changes to your Functions code or to the `environment.yaml` file.
34
36
35
-
## Exposing the server
37
+
## Exposing the Server
36
38
37
39
To enable your CIM Database Cloud instance to send webhook requests to your Functions, you need to make the server accessible from the internet. Here are several ways to do this:
38
40
@@ -50,26 +52,25 @@ If you are developing Functions locally, you can use services like [ngrok](https
50
52
51
53
Please refer to the documentation of the specific service for instructions on how to do this.
52
54
53
-
54
-
## Create a webhook in CIM Database Cloud
55
+
## Create a Webhook in CIM Database Cloud
55
56
56
57
To test your Functions locally, create a webhook in your CIM Database Cloud instance and point it to your development server.
57
58
58
59
The webhook URL should combine your development server URL with the Function name from your `environment.yaml` file using this format:
Make sure to set the webhooks event to the correct event you want to test with your Function.
69
+
Make sure to set the webhook's event to the correct event you want to test with your Function.
68
70
69
71
For more detailed information on how to create a webhook in CIM Database Cloud, please refer to the [CIM Database Cloud documentation](https://saas-docs.contact-cloud.com/2025.7.0-en/admin/admin-contact_cloud/saas_admin/webhooks).
70
72
71
-
72
-
## Securing the development server
73
+
## Securing the Development Server
73
74
74
75
Since the development server is exposed to the outside world, you should secure it to prevent unauthorized access.
Copy file name to clipboardExpand all lines: docs/examples/enforce_field_rules.md
+14-15Lines changed: 14 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
Functions can be used to validate user input and thus ensure that fields on e.g. parts or documents are filled out correctly.
1
+
Functions can be used to validate user input and ensure that fields on, for example, parts or documents are filled out correctly.
2
2
3
3
4
4
### Required field based on Part category
5
-
This example shows how you can enforce parts of category *"Single Part"*to have a material assigned to them.
5
+
This example shows how you can enforce that parts in the category *"Single Part"*must have a material assigned.
6
6
7
-
The example Function can be connected to the [PartCreateCheckEvent](../reference/events.md#partcreatecheckevent) and [PartModifyCheckEvent](../reference/events.md#partmodifycheckevent) and will return an [AbortAndShowErrorAction](../reference/actions.md#abortandshowerroraction) to abort the creation or modification of the part if the condition is not met.
7
+
The example Function can be connected to the [PartCreateCheckEvent](../reference/events.md#partcreatecheckevent) and [PartModifyCheckEvent](../reference/events.md#partmodifycheckevent). It will return an [AbortAndShowErrorAction](../reference/actions.md#abortandshowerroraction) to abort the creation or modification of the part if the condition is not met.
If a part of category 'Single Part' is created, a material has to be assigned.
24
+
If a part of category 'Single Part' is created or modified, a material must be assigned.
25
25
This should be checked when the part is created or modified.
26
26
"""
27
27
28
28
for part in event.data.parts:
29
-
#the event contains a list of parts that are about to be created
29
+
#The event contains a list of parts that are about to be created or modified
30
30
if part.t_kategorie_name_en =="Single Part"andnot part.material_object_id:
31
31
return AbortAndShowErrorAction(
32
-
message="A material has to be assigned to a part of category 'Single Part'."
32
+
message="A material must be assigned to a part of category 'Single Part'."
33
33
)
34
34
35
35
```
36
36
37
37
### Require parts to be classified before release
38
38
39
-
Classification is a powerful tool for organizing your parts, however the best tool only works if users use it.
40
-
With this example Function you can require parts to be classified before they can be released.
39
+
Classification is a powerful tool for organizing your parts. However, even the best tool is only effective if users actually use it.
40
+
With this example Function, you can require that parts are classified before they can be released.
41
41
42
-
This Function should be connected to the [PartReleaseCheckEvent](../reference/events.md#partreleasecheckevent) and will return an [AbortAndShowErrorAction](../reference/actions.md#abortandshowerroraction) to prevent the release, if classification data is missing.
42
+
This Function should be connected to the [PartReleaseCheckEvent](../reference/events.md#partreleasecheckevent) and will return an [AbortAndShowErrorAction](../reference/actions.md#abortandshowerroraction) to prevent the release if classification data is missing.
43
43
44
-
The example code shows you how to fetch classification data for parts from the [CIM Database Cloud GraphQL API](https://saas-docs.contact-cloud.com/latest-en/admin/admin-contact_cloud/saas_admin/webhooks_graphql){:target="_blank"}. The Function then checks if any classification data is present, however you can easily expand this to check for specific classes.
44
+
The example code demonstrates how to fetch classification data for parts from the [CIM Database Cloud GraphQL API](https://saas-docs.contact-cloud.com/latest-en/admin/admin-contact_cloud/saas_admin/webhooks_graphql){:target="_blank"}. The Function then checks if any classification data is present, but you can easily expand this to check for specific classes.
45
45
46
46
```python
47
47
from csfunctions import MetaData, Service
48
48
from csfunctions.actions import AbortAndShowErrorAction
Copy file name to clipboardExpand all lines: docs/examples/field_calculation.md
+18-24Lines changed: 18 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
# Field calculation
2
2
3
-
The data sheet editor in CIM Database Cloud already allows you to define some basic [field calculations](https://saas-docs.contact-cloud.com/2025.13.1-en/admin/admin-contact_cloud/saas_admin/app_setup_data_edit_field_calc){:target="_blank"} to fill out fields automatically.
3
+
The datasheet editor in CIM Database Cloud already allows you to define some basic [field calculations](https://saas-docs.contact-cloud.com/2025.13.1-en/admin/admin-contact_cloud/saas_admin/app_setup_data_edit_field_calc){:target="_blank"} to fill out fields automatically.
4
4
5
-
However, the Python expressions available in the datasheet editor are limited. Functions allow for much more freedom in defining your field calculations, and allow you to do things like *"fetching external data"* or *"referencing other objects"*.
5
+
However, the Python expressions available in the datasheet editor are limited. Functions allow for much more flexibility in defining your field calculations, enabling you to do things like *fetching external data* or *referencing other objects*.
6
6
7
-
Field calculations with Functions utilize the "<Object\>FieldCalulationEvent", e.g. [PartFieldCalculationEvent](../reference/events.md#partfieldcalculationevent), which expect the response to contain a `DataResponse` with a dictionary containing the fields that should be updated.
7
+
Field calculations with Functions utilize the `<Object>FieldCalculationEvent`, e.g. [PartFieldCalculationEvent](../reference/events.md#partfieldcalculationevent), which expects the response to contain a `DataResponse` with a dictionary of the fields that should be updated.
8
8
9
9
```python
10
-
return DataResponse(data={somefield="new value"})
10
+
return DataResponse(data={"somefield": "new value"})
11
11
```
12
12
13
13
14
14
## Custom part number for external parts
15
15
16
-
This example shows you the basics of calculating fields with Functions and how to use the `service` parameter to generate a fresh number.
16
+
This example shows you the basics of calculating fields with Functions and how to use the `service` parameter to generate a new number.
17
17
18
18
The example Function checks if the part is an *"External"* part and generates a custom part number for it.
19
19
@@ -23,59 +23,53 @@ from csfunctions.events import PartFieldCalculationEvent
You can check `event.data.action` to decide for which operations (*copy*,*create*,*index* and *modify*) you want your field calculation to return a new value.
58
-
Some fields, like part number (*teilenummer*) can only be set during the initial creation.
51
+
You can check `event.data.action` to decide for which operations (*copy*,*create*,*index*, and *modify*) you want your field calculation to return a new value.
52
+
Some fields, like part number (*teilenummer*), can only be set during the initial creation.
59
53
60
54
## Translate a field with DeepL
61
55
62
-
Inside Functions you can fetch data from external systems and fill out fields based on that data. This is something that would not be possible with the field calculations in the datasheet editor. You could use this for example to fetch new part numbers from an ERP system.
56
+
Inside Functions, you can fetch data from external systems and fill out fields based on that data. This is something that would not be possible with the field calculations in the datasheet editor. For example, you could use this to fetch new part numbers from an ERP system.
63
57
64
-
This example uses the API from [DeepL](https://www.deepl.com) to translate a field from German to English. The example uses the additional attributes 1 and 2 on parts, but you can of course change that to any attributes that fit your use-case.
58
+
This example uses the API from [DeepL](https://www.deepl.com) to translate a field from German to English. The example uses the additional attributes 1 and 2 on parts, but you can of course change that to any attributes that fit your usecase.
65
59
66
60
```python
67
61
import os
68
62
from csfunctions import DataResponse
69
63
from csfunctions.events import PartFieldCalculationEvent
70
64
import requests
71
65
72
-
#set the DEEPL_API_KEY during deployment like this:
66
+
#Set the DEEPL_API_KEY during deployment like this:
73
67
# cfc env deploy <environment name> --environment-variables "DEEPL_API_KEY=<your API key>"
Functions can interact with workflows. You can trigger Functions from within workflows using the [Trigger Webhook](https://saas-docs.contact-cloud.com/latest-en/admin/admin-contact_cloud/saas_admin/webhooks_workflow){:target="_blank"} task and you can even start new workflows by using the [StartWorkflowAction](../reference/actions.md#startworkflowaction)!
3
+
Functions can interact with workflows. You can trigger Functions from within workflows using the [Trigger Webhook](https://saas-docs.contact-cloud.com/latest-en/admin/admin-contact_cloud/saas_admin/webhooks_workflow){:target="_blank"} task, and you can even start new workflows by using the [StartWorkflowAction](../reference/actions.md#startworkflowaction)!
4
4
5
5
6
-
## Start workflow on EC status change
6
+
## Start a workflow on EC status change
7
7
8
-
This example shows you how to start a workflow template in response to an engineering change status change.
8
+
This example shows how to start a workflow template in response to an engineering change status change.
9
9
10
10
!!! note
11
-
Starting workflows in response to engineering change status changes is already possible in CIM Database Cloud without the use of Functions. However Functions allow you to dynamically select different templates and fill out task parameters, based on the nature of the change.
11
+
Starting workflows in response to engineering change status changes is already possible in CIM Database Cloud without the use of Functions. However, Functions allow you to dynamically select different templates and fill out task parameters based on the nature of the change.
12
12
13
-
This example uses a very simple template, containing just an *information task*. If an engineering change contains external parts, users with the *External Part Manager* Role should be notified of the planned change during the evaluation phase.
14
-
15
-
You can easily adapt this example to your use-case, by adding additional tasks to the template or changing the conditions under which the workflow should be started.
13
+
This example uses a very simple template containing just an *information task*. If an engineering change contains external parts, users with the *External Part Manager* role should be notified of the planned change during the evaluation phase.
16
14
15
+
You can easily adapt this example to your use case by adding additional tasks to the template or changing the conditions under which the workflow should be started.
17
16
18
17
```python
19
18
from csfunctions.actions.start_workflow import (
@@ -24,7 +23,7 @@ from csfunctions.actions.start_workflow import (
24
23
from csfunctions.events import EngineeringChangeStatusChangedEvent
0 commit comments