> For the complete documentation index, see [llms.txt](https://docs.ngsurvey.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ngsurvey.com/ar/form-management/form-designer/idraj-albyanat/idraj-javascript.md).

# إدراج Javascript

باستخدام piping في javascript، من الممكن تمرير قيمة سيتم إنشاؤها باستخدام أي javascript من اختيارك.

يمكن إعداد دالة NGSJS خاصة لإرجاع ناتج شفرة javascript الخاصة بك، ويمكن بعد ذلك تخزين الناتج في قيمة افتراضية لعرضه وتخزينه داخل حقل

{% hint style="warning" %}
لن يتم تقييم الناتج إلا أثناء وضع الإرسال، وإذا تم إرسال إجابات الاستبيان وأنت في وضع التغيير أو وضع الاستئناف، فستكون القيمة هي القيمة الأصلية التي تم حفظها قبل استئناف الإجابات أو تغييرها&#x20;
{% endhint %}

## ➕مثال جمع الحقول البسيطة

فيما يلي الخطوات لإضافة JavaScript مخصص يجمع حقلين. يمكنك تعديل الشفرة لتحقيق أي ناتج مطلوب لتخزينه. لاحظ أنه إذا كنت تحتاج فقط إلى الجمع، فقد تفكر في استخدام [حقل رقمي](/ar/form-management/form-designer/answers/answer-types/numeric-answer-field.md) النوع بدلاً من ذلك\
\
أنشئ سؤالاً بثلاثة حقول

<figure><img src="https://848173432-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8fLhS0bmfBRyq0HdUm%2Fuploads%2FIDSCUF2C0iRyeJJxdaoq%2Fimage.png?alt=media&amp;token=bb349156-efe1-48b3-a483-15d43a5272d3" alt=""><figcaption></figcaption></figure>

بعد إنشائه لكل حقل مشارك في العملية الحسابية، عيّن في خصائص إجابته Pipe alias الخاص به، وسيُستخدم هذا لاحقًا للبحث عن القيمة الحالية.\
\
![](https://848173432-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8fLhS0bmfBRyq0HdUm%2Fuploads%2FJuItIOSUq2htDrtBBwBE%2Fimage.png?alt=media\&token=ab493fe1-bbe1-4463-84aa-8783f26c6e6e)\
\
![](https://848173432-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8fLhS0bmfBRyq0HdUm%2Fuploads%2FKSM0y8SySzSHRaFiFKba%2Fimage.png?alt=media\&token=97408231-a426-4cb5-8d4e-c29d5acffda0)\
\
\
في حقل النتيجة، افتح إعدادات الإجابة وفي قيمة النص الافتراضية استخدم دالة NGSJS للحصول على قيمة الحقلين الآخرين وإخراج النتيجة\ <br>

<figure><img src="https://848173432-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8fLhS0bmfBRyq0HdUm%2Fuploads%2FdEcLPPRZRtgcZfjdiCTI%2Fimage.png?alt=media&amp;token=aaea9927-3abd-4edb-832e-d2e954d53ab2" alt=""><figcaption></figcaption></figure>

```
NGSJS(return pipeContext.getAnswer('VALUEA') + pipeContext.getAnswer('VALUEB'))
```

## 👨‍💻️ pipeContext

pipeContext هو كائن مدمج يوفّر لك الخيارات التالية:\
\
**الخصائص:**

* `questions: Question[]`\
  قائمة أسئلة الاستبيان.
* `answers: Answer[]`\
  قائمة الإجابات الممكنة عبر جميع الأسئلة.
* `respondent: Respondent`\
  معلومات المستجيب الحالي.
* `panelists: Panelist[]`\
  أعضاء اللوحة المرتبطون (إن وجد).
* `respondentAnswers: RespondentAnswer[]`\
  الإجابات المقدمة من المستجيب.
* `pipeDataAttributesValues: PipeDataAttributeValue[]`\
  سمات وقيم بيانات إضافية لـ pipe.

#### الأساليب

**`getAnswer(id: string): string`**

يُرجع القيمة (القيم) المرتبطة بمعرّف محدد.

* يدعم البحث حسب:
  * معرّف الإجابة
  * معرّف السؤال
  * Reporting alias
  * Pipe alias
* السلوك:
  * إذا كان المعرّف يطابق **إجابة نصية**، فيُرجع قيمتها.
  * إذا كان يطابق **سؤال**، فيُرجع الإجابات المحددة.
  * تُرجع القيم المتعددة كسلسلة مفصولة بفواصل.

**`isSelectedAnswer(id: string, value: string): boolean`**

يتحقق مما إذا كانت إجابة محددة قد تم اختيارها.

* المعلمات:
  * `id`: معرّف السؤال أو الإجابة
  * `value`: معرّف الإجابة أو القيمة المراد التحقق منها
* السلوك:
  * إذا كان `id` يشير إلى سؤال → يتحقق مما إذا كانت الإجابة المحددة قد تم اختيارها.
  * إذا كان `id` يشير إلى إجابة → يقارن قيمتها مباشرةً.
* يُرجع:
  * `true` إذا كانت الإجابة محددة أو مطابقة
  * `false` بخلاف ذلك


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ngsurvey.com/ar/form-management/form-designer/idraj-albyanat/idraj-javascript.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
